
<!DOCTYPE HTML>
<html lang="zh-hans" >
<head>
    <meta charset="UTF-8">
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
    <title>14.5：Flutter图片加载与缓存 · 《Flutter实战》</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="baidu-site-verification" content="Y34sAqDKUH"/>
    <meta name="theme-color" content="#ffffff">
    <!--<meta name="description" content="">-->
    <meta name="description" content="《Flutter实战》是Flutter中文网（https://flutterchina.club）开源的电子书，旨在帮助开发者系统化的了解并学习Flutter。">
    <meta name="keywords" content="flutter实战,flutter书籍,flutter电子书,flutter中文网 ">
    <meta name="generator" content="GitBook 3.2.3">
    
    <meta name="author" content="wendux 824783146@qq.com">
    
    
    
    
    <link rel="stylesheet" href="https://pcdn.flutterchina.club/gitbook/style.css">

    
    
    
    <link rel="stylesheet" href="https://pcdn.flutterchina.club/gitbook/gitbook-plugin-search-pro/search.css">
    
    
    
    <link rel="stylesheet" href="https://pcdn.flutterchina.club/gitbook/gitbook-plugin-ace/ace.css">
    
    
    
    <link rel="stylesheet" href="https://pcdn.flutterchina.club/gitbook/gitbook-plugin-splitter/splitter.css">
    
    
    
    <link rel="stylesheet" href="https://pcdn.flutterchina.club/gitbook/gitbook-plugin-prism/prism.css">
    
    
    
    <link rel="stylesheet" href="https://pcdn.flutterchina.club/gitbook/gitbook-plugin-donate/plugin.css">
    
    
    
    <link rel="stylesheet" href="https://pcdn.flutterchina.club/gitbook/gitbook-plugin-fontsettings/website.css">
    
    
    

    

    
        
    
        
    
        
    
        
    
        
    

    
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="https://pcdn.flutterchina.club/gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="https://pcdn.flutterchina.club/gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="../chapter15/intro.html" />
    
    
    <link rel="prev" href="flutter_app_startup.html" />
    

    <style>
        .pull-right > i {
            font-size: 25px;
            color: #777 !important;
            cursor: pointer;

        }

        .pull-right > i:hover {
            color: #777 !important;
        }

        body {
            font-size: 15px !important;
        }

        a[href='../todo.html'], a[href='todo.html'] {
            color: #888 !important;
        }

        .copyright {
            text-align: center;
            margin: 80px 16px 8px 16px;
            padding-top: 16px;
            border-top: #eee 1px solid;
            color: grey;
            font-size: .9em;
        }

        .f-links a{
            text-decoration: underline;
            color: dodgerblue !important;
        }

        .f-links a:hover{
            opacity: .8 !important;
        }

        /*.ad {*/
            /*color: white;*/
            /*text-align: center;*/
            /*background: url(https://img.alicdn.com/tfs/TB1Huu7vMmTBuNjy1XbXXaMrVXa-2880-400.png);*/
            /*background-size: cover;*/
            /*cursor: pointer;*/
            /*margin-bottom: 30px;*/
            /*padding: 18px*/
        /*}*/

        /*.ad:hover {*/
            /*opacity: .8;*/
        /*}*/

        .buy-btn {
            text-decoration: none !important;
            padding: 8px 18px;
            border: #268bd2 1px solid !important;
            display: inline-block !important;
            border-radius: 25px;
            color: #268bd2;
            margin-top: 10px;
        }

        .buy-btn:hover {
            transition: all ease 200ms;
            box-shadow: #555 2px 5px 10px;
            background: #eee;
            color: dodgerblue !important;
        }

        .maoyun{
            padding-top: 5px;
        }


    </style>
</head>
<body>
<!--<div id="ad" style="display: none">-->
<!--<div class="ad ad0"-->
<!--onclick="_track('aliyun','https://promotion.aliyun.com/ntms/yunparter/invite.html?userCode=8hhi4dts')">-->
<!--<div style="font-size: 1.3em; padding-right: 120px; position: relative; top: 12px">阿里云新春特惠</div>-->
<!--<div style="color:orange; font-size: 13px">限时红包 最高￥<span style="font-size: 40px">1888</span></div>-->
<!--</div>-->
<!--<div class="ad ad1"-->
<!--onclick="_track('aliyun-puhui','https://promotion.aliyun.com/ntms/act/qwbk.html?spm=5176.11533457.1089570.10.74e877e33jtaGy&userCode=8hhi4dts')">-->
<!--<div style="font-size: 1.5em;">阿里云全民云计算-新春特惠</div>-->
<!--<div style="color:orange; font-size: 18px;padding-top: 4px;">普惠上云，云服务器1核1G仅需293元/年</div>-->
<!--</div>-->
<!--</div>-->

<div class="ad"  style="text-align:center; padding-bottom:30px; display: none"><a href="https://item.jd.com/12816296.html" onclick="buy('img')" title='点击购买' target="_blank"><img style="height:250px;box-shadow: #aaa 5px 5px 10px;" src="https://pcdn.flutterchina.club/imgs/book.png"/></a>  <br/> <a class="buy-btn" onclick="buy('btn')" href="https://item.jd.com/12816296.html" title='点击购买' target="_blank"> 购买实体书 </a></div>


<!--<div class="ad"  style="text-align:center; padding-bottom:30px; display: none"><a href="https://item.jd.com/12816296.html" onclick="buy('img')" title='点击购买' target="_blank"><img style="height:250px;box-shadow: #aaa 5px 5px 10px;" src="https://pcdn.flutterchina.club/imgs/book.png"/></a>  <br/> <a class="buy-btn" onclick="buy('img')" href="https://item.jd.com/12816296.html" title='点击购买' target="_blank"> 购买实体书 </a>-->
    <!--<a id="jd" href="https://item.jd.com/12816296.html" onclick="buy('jd')"  style=" display: block; padding: 10px; color: red; text-decoration: underline; ">即日起至4.23日，京东图书每满100减50！ </a>-->
<!--</div>-->


<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    
    
        
        <li>
            <a href="https://flutterchina.club" target="_blank" class="custom-link"><div><img height=20 style='position:relative; top:5px; padding-right:5px ' src='https://cdn.jsdelivr.net/gh/flutterchina/website@1.0/images/favicon.png'/> Flutter中文网</div></a>
        </li>
    
    

    
    <li class="divider"></li>
    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../intro.html">
            
                <a href="../intro.html">
            
                    
                    前言
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">入门篇</li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="../chapter1/">
            
                <a href="../chapter1/">
            
                    
                    第一章：起步
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1.1" data-path="../chapter1/mobile_development_intro.html">
            
                <a href="../chapter1/mobile_development_intro.html">
            
                    
                    1.1：移动开发技术简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.2" data-path="../chapter1/flutter_intro.html">
            
                <a href="../chapter1/flutter_intro.html">
            
                    
                    1.2：初识Flutter
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.3" data-path="../chapter1/install_flutter.html">
            
                <a href="../chapter1/install_flutter.html">
            
                    
                    1.3：搭建Flutter开发环境
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.4" data-path="../chapter1/dart.html">
            
                <a href="../chapter1/dart.html">
            
                    
                    1.4：Dart语言简介
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="../chapter2/">
            
                <a href="../chapter2/">
            
                    
                    第二章：第一个Flutter应用
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.2.1" data-path="../chapter2/first_flutter_app.html">
            
                <a href="../chapter2/first_flutter_app.html">
            
                    
                    2.1：计数器示例
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2.2" data-path="../chapter2/flutter_router.html">
            
                <a href="../chapter2/flutter_router.html">
            
                    
                    2.2：路由管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2.3" data-path="../chapter2/flutter_package_mgr.html">
            
                <a href="../chapter2/flutter_package_mgr.html">
            
                    
                    2.3：包管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2.4" data-path="../chapter2/flutter_assets_mgr.html">
            
                <a href="../chapter2/flutter_assets_mgr.html">
            
                    
                    2.4：资源管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2.5" data-path="../chapter2/flutter_app_debug.html">
            
                <a href="../chapter2/flutter_app_debug.html">
            
                    
                    2.5：调试Flutter APP
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2.6" data-path="../chapter2/thread_model_and_error_report.html">
            
                <a href="../chapter2/thread_model_and_error_report.html">
            
                    
                    2.6：Dart线程模型及异常捕获
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="../chapter3/">
            
                <a href="../chapter3/">
            
                    
                    第三章：基础组件
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.3.1" data-path="../chapter3/flutter_widget_intro.html">
            
                <a href="../chapter3/flutter_widget_intro.html">
            
                    
                    3.1：Widget简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.2" data-path="../chapter3/state_manage.html">
            
                <a href="../chapter3/state_manage.html">
            
                    
                    3.2：状态管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.3" data-path="../chapter3/text.html">
            
                <a href="../chapter3/text.html">
            
                    
                    3.3：文本、字体样式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.4" data-path="../chapter3/buttons.html">
            
                <a href="../chapter3/buttons.html">
            
                    
                    3.4：按钮
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.5" data-path="../chapter3/img_and_icon.html">
            
                <a href="../chapter3/img_and_icon.html">
            
                    
                    3.5：图片和Icon
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.6" data-path="../chapter3/radio_and_checkbox.html">
            
                <a href="../chapter3/radio_and_checkbox.html">
            
                    
                    3.6：单选框和复选框
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.7" data-path="../chapter3/input_and_form.html">
            
                <a href="../chapter3/input_and_form.html">
            
                    
                    3.7：输入框和表单
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.8" data-path="../chapter3/progress.html">
            
                <a href="../chapter3/progress.html">
            
                    
                    3.8：进度指示器
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="../chapter4/">
            
                <a href="../chapter4/">
            
                    
                    第四章：布局类组件
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.4.1" data-path="../chapter4/intro.html">
            
                <a href="../chapter4/intro.html">
            
                    
                    4.1：布局类组件简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4.2" data-path="../chapter4/row_and_column.html">
            
                <a href="../chapter4/row_and_column.html">
            
                    
                    4.2：线性布局（Row、Column）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4.3" data-path="../chapter4/flex.html">
            
                <a href="../chapter4/flex.html">
            
                    
                    4.3：弹性布局（Flex）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4.4" data-path="../chapter4/wrap_and_flow.html">
            
                <a href="../chapter4/wrap_and_flow.html">
            
                    
                    4.4：流式布局（Wrap、Flow）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4.5" data-path="../chapter4/stack.html">
            
                <a href="../chapter4/stack.html">
            
                    
                    4.5：层叠布局（Stack、Positioned）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4.6" data-path="../chapter4/alignment.html">
            
                <a href="../chapter4/alignment.html">
            
                    
                    4.6：对齐与相对定位（Align）
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="../chapter5/">
            
                <a href="../chapter5/">
            
                    
                    第五章：容器类组件
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.5.1" data-path="../chapter5/padding.html">
            
                <a href="../chapter5/padding.html">
            
                    
                    5.1：填充（Padding）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.5.2" data-path="../chapter5/constrainedbox_and_sizebox.html">
            
                <a href="../chapter5/constrainedbox_and_sizebox.html">
            
                    
                    5.2：尺寸限制类容器（ConstrainedBox等）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.5.3" data-path="../chapter5/decoratedbox.html">
            
                <a href="../chapter5/decoratedbox.html">
            
                    
                    5.3：装饰容器（DecoratedBox）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.5.4" data-path="../chapter5/transform.html">
            
                <a href="../chapter5/transform.html">
            
                    
                    5.4：变换（Transform）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.5.5" data-path="../chapter5/container.html">
            
                <a href="../chapter5/container.html">
            
                    
                    5.5：Container容器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.5.6" data-path="../chapter5/material_scaffold.html">
            
                <a href="../chapter5/material_scaffold.html">
            
                    
                    5.6：Scaffold、TabBar、底部导航
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.5.7" data-path="../chapter5/clip.html">
            
                <a href="../chapter5/clip.html">
            
                    
                    5.7：剪裁（Clip）
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.6" data-path="../chapter6/">
            
                <a href="../chapter6/">
            
                    
                    第六章：可滚动组件
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.6.1" data-path="../chapter6/intro.html">
            
                <a href="../chapter6/intro.html">
            
                    
                    6.1：可滚动组件简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.2" data-path="../chapter6/single_child_scrollview.html">
            
                <a href="../chapter6/single_child_scrollview.html">
            
                    
                    6.2：SingleChildScrollView
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.3" data-path="../chapter6/listview.html">
            
                <a href="../chapter6/listview.html">
            
                    
                    6.3：ListView
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.4" data-path="../chapter6/gridview.html">
            
                <a href="../chapter6/gridview.html">
            
                    
                    6.4：GridView
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.5" data-path="../chapter6/custom_scrollview.html">
            
                <a href="../chapter6/custom_scrollview.html">
            
                    
                    6.5：CustomScrollView
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.6" data-path="../chapter6/scroll_controller.html">
            
                <a href="../chapter6/scroll_controller.html">
            
                    
                    6.6：滚动监听及控制（ScrollController）
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.7" data-path="../chapter7/">
            
                <a href="../chapter7/">
            
                    
                    第七章：功能型组件
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.7.1" data-path="../chapter7/willpopscope.html">
            
                <a href="../chapter7/willpopscope.html">
            
                    
                    7.1：导航返回拦截（WillPopScope）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.7.2" data-path="../chapter7/inherited_widget.html">
            
                <a href="../chapter7/inherited_widget.html">
            
                    
                    7.2：数据共享（InheritedWidget）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.7.3" data-path="../chapter7/provider.html">
            
                <a href="../chapter7/provider.html">
            
                    
                    7.3： 跨组件状态共享（Provider）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.7.4" data-path="../chapter7/theme.html">
            
                <a href="../chapter7/theme.html">
            
                    
                    7.4：颜色和主题（Theme）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.7.5" data-path="../chapter7/futurebuilder_and_streambuilder.html">
            
                <a href="../chapter7/futurebuilder_and_streambuilder.html">
            
                    
                    7.5：异步UI更新（FutureBuilder、StreamBuilder）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.7.6" data-path="../chapter7/dailog.html">
            
                <a href="../chapter7/dailog.html">
            
                    
                    7.6：对话框详解
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="header">进阶篇</li>
        
        
    
        <li class="chapter " data-level="3.1" data-path="../chapter8/">
            
                <a href="../chapter8/">
            
                    
                    第八章：事件处理与通知
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1.1" data-path="../chapter8/listener.html">
            
                <a href="../chapter8/listener.html">
            
                    
                    8.1：原始指针事件处理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.2" data-path="../chapter8/gesture.html">
            
                <a href="../chapter8/gesture.html">
            
                    
                    8.2：手势识别
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.3" data-path="../chapter8/eventbus.html">
            
                <a href="../chapter8/eventbus.html">
            
                    
                    8.3：全局事件总线
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.4" data-path="../chapter8/notification.html">
            
                <a href="../chapter8/notification.html">
            
                    
                    8.4：通知(Notification)
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="../chapter9/">
            
                <a href="../chapter9/">
            
                    
                    第九章：动画
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.2.1" data-path="../chapter9/intro.html">
            
                <a href="../chapter9/intro.html">
            
                    
                    9.1：Flutter动画简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2.2" data-path="../chapter9/animation_structure.html">
            
                <a href="../chapter9/animation_structure.html">
            
                    
                    9.2：动画结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2.3" data-path="../chapter9/route_transition.html">
            
                <a href="../chapter9/route_transition.html">
            
                    
                    9.3：自定义路由过渡动画
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2.4" data-path="../chapter9/hero.html">
            
                <a href="../chapter9/hero.html">
            
                    
                    9.4：Hero动画
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2.5" data-path="../chapter9/stagger_animation.html">
            
                <a href="../chapter9/stagger_animation.html">
            
                    
                    9.5：交织动画
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2.6" data-path="../chapter9/animated_switcher.html">
            
                <a href="../chapter9/animated_switcher.html">
            
                    
                    9.6：通用“动画切换”组件（AnimatedSwitcher）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2.7" data-path="../chapter9/animated_widgets.html">
            
                <a href="../chapter9/animated_widgets.html">
            
                    
                    9.7：动画过渡组件
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="../chapter10/">
            
                <a href="../chapter10/">
            
                    
                    第十章：自定义组件
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.3.1" data-path="../chapter10/intro.html">
            
                <a href="../chapter10/intro.html">
            
                    
                    10.1：自定义组件方法简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3.2" data-path="../chapter10/combine.html">
            
                <a href="../chapter10/combine.html">
            
                    
                    10.2：组合现有组件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3.3" data-path="../chapter10/turn_box.html">
            
                <a href="../chapter10/turn_box.html">
            
                    
                    10.3：组合实例：TurnBox
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3.4" data-path="../chapter10/custom_paint.html">
            
                <a href="../chapter10/custom_paint.html">
            
                    
                    10.4：自绘组件（CustomPaint与Canvas）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3.5" data-path="../chapter10/gradient_circular_progress_demo.html">
            
                <a href="../chapter10/gradient_circular_progress_demo.html">
            
                    
                    10.5：自绘实例：圆形渐变进度条(自绘)
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="../chapter11/">
            
                <a href="../chapter11/">
            
                    
                    第十一章：文件操作与网络请求
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.4.1" data-path="../chapter11/file_operation.html">
            
                <a href="../chapter11/file_operation.html">
            
                    
                    11.1：文件操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4.2" data-path="../chapter11/http.html">
            
                <a href="../chapter11/http.html">
            
                    
                    11.2：Http请求-HttpClient
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4.3" data-path="../chapter11/dio.html">
            
                <a href="../chapter11/dio.html">
            
                    
                    11.3：Http请求-Dio package
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4.4" data-path="../chapter11/download_with_chunks.html">
            
                <a href="../chapter11/download_with_chunks.html">
            
                    
                    11.4：实例：Http分块下载
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4.5" data-path="../chapter11/websocket.html">
            
                <a href="../chapter11/websocket.html">
            
                    
                    11.5：WebSocket
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4.6" data-path="../chapter11/socket.html">
            
                <a href="../chapter11/socket.html">
            
                    
                    11.6：使用Socket API
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4.7" data-path="../chapter11/json_model.html">
            
                <a href="../chapter11/json_model.html">
            
                    
                    11.7：Json转Dart Model类
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.5" data-path="../chapter12/">
            
                <a href="../chapter12/">
            
                    
                    第十二章：包与插件
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.5.1" data-path="../chapter12/develop_package.html">
            
                <a href="../chapter12/develop_package.html">
            
                    
                    12.1：开发package
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.5.2" data-path="../chapter12/platform-channel.html">
            
                <a href="../chapter12/platform-channel.html">
            
                    
                    12.2：平台通道简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.5.3" data-path="../chapter12/develop_plugin.html">
            
                <a href="../chapter12/develop_plugin.html">
            
                    
                    12.3：开发Flutter插件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.5.4" data-path="../chapter12/android_implement.html">
            
                <a href="../chapter12/android_implement.html">
            
                    
                    12.4：插件开发：实现Android端API
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.5.5" data-path="../chapter12/ios_implement.html">
            
                <a href="../chapter12/ios_implement.html">
            
                    
                    12.5：插件开发：实现IOS端API
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.5.6" data-path="../chapter12/texture_platformview.html">
            
                <a href="../chapter12/texture_platformview.html">
            
                    
                    12.6：Texture和PlatformView
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.6" data-path="../chapter13/">
            
                <a href="../chapter13/">
            
                    
                    第十三章：国际化
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.6.1" data-path="../chapter13/multi_languages_support.html">
            
                <a href="../chapter13/multi_languages_support.html">
            
                    
                    13.1：让App支持多语言
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.6.2" data-path="../chapter13/locallization_implement.html">
            
                <a href="../chapter13/locallization_implement.html">
            
                    
                    13.2：实现Localizations
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.6.3" data-path="../chapter13/intl.html">
            
                <a href="../chapter13/intl.html">
            
                    
                    13.3：使用Intl包
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.6.4" data-path="../chapter13/faq.html">
            
                <a href="../chapter13/faq.html">
            
                    
                    13.4：国际化常见问题
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.7" data-path="./">
            
                <a href="./">
            
                    
                    第十四章：Flutter核心原理
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.7.1" data-path="flutter_ui_system.html">
            
                <a href="flutter_ui_system.html">
            
                    
                    14.1：Flutter UI系统
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.7.2" data-path="element_buildcontext.html">
            
                <a href="element_buildcontext.html">
            
                    
                    14.2：Element和BuildContext
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.7.3" data-path="render_object.html">
            
                <a href="render_object.html">
            
                    
                    14.3：RenderObject与RenderBox
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.7.4" data-path="flutter_app_startup.html">
            
                <a href="flutter_app_startup.html">
            
                    
                    14.4：Flutter从启动到显示
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="3.7.5" data-path="image_and_cache.html">
            
                <a href="image_and_cache.html">
            
                    
                    14.5：Flutter图片加载与缓存
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="header">实例篇</li>
        
        
    
        <li class="chapter " data-level="4.1" data-path="../chapter15/intro.html">
            
                <a href="../chapter15/intro.html">
            
                    
                    第十五章：一个完整的Flutter应用
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1.1" data-path="../chapter15/intro.html">
            
                <a href="../chapter15/intro.html">
            
                    
                    15.1：应用简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.2" data-path="../chapter15/code_structure.html">
            
                <a href="../chapter15/code_structure.html">
            
                    
                    15.2：APP代码结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.3" data-path="../chapter15/models.html">
            
                <a href="../chapter15/models.html">
            
                    
                    15.3：Model类定义
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.4" data-path="../chapter15/globals.html">
            
                <a href="../chapter15/globals.html">
            
                    
                    15.4：全局变量及共享状态
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.5" data-path="../chapter15/network.html">
            
                <a href="../chapter15/network.html">
            
                    
                    15.5：网络请求封装
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.6" data-path="../chapter15/entry.html">
            
                <a href="../chapter15/entry.html">
            
                    
                    15.6：App入口及首页
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.7" data-path="../chapter15/login_page.html">
            
                <a href="../chapter15/login_page.html">
            
                    
                    15.7：登录页
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.8" data-path="../chapter15/language_and_theme_setting.html">
            
                <a href="../chapter15/language_and_theme_setting.html">
            
                    
                    15.8：多语言和多主题
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="https://pcdn.flutterchina.club/gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    
    <a class="btn pull-right" aria-label="GitHub">
        <i class="fa fa-edit" title="编辑本文"></i>
    </a>
    <a class="btn pull-right" aria-label="GitHub" href="https://github.com/flutterchina/flutter-in-action">
        <i class="fa fa-github" title="查看本书开源项目"></i>
    </a>
    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >14.5：Flutter图片加载与缓存</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="145-&#x56FE;&#x7247;&#x52A0;&#x8F7D;&#x539F;&#x7406;&#x4E0E;&#x7F13;&#x5B58;">14.5 &#x56FE;&#x7247;&#x52A0;&#x8F7D;&#x539F;&#x7406;&#x4E0E;&#x7F13;&#x5B58;</h1>
<p>&#x5728;&#x672C;&#x4E66;&#x524D;&#x9762;&#x7AE0;&#x8282;&#x5DF2;&#x7ECF;&#x4ECB;&#x7ECD;&#x8FC7;<code>Image</code> &#x7EC4;&#x4EF6;&#xFF0C;&#x5E76;&#x63D0;&#x5230;Flutter&#x6846;&#x67B6;&#x5BF9;&#x52A0;&#x8F7D;&#x8FC7;&#x7684;&#x56FE;&#x7247;&#x662F;&#x6709;&#x7F13;&#x5B58;&#x7684;&#xFF08;&#x5185;&#x5B58;&#xFF09;&#xFF0C;&#x9ED8;&#x8BA4;&#x6700;&#x5927;&#x7F13;&#x5B58;&#x6570;&#x91CF;&#x662F;1000&#xFF0C;&#x6700;&#x5927;&#x7F13;&#x5B58;&#x7A7A;&#x95F4;&#x4E3A;100M&#x3002;&#x672C;&#x8282;&#x4FBF;&#x8BE6;&#x7EC6;&#x4ECB;&#x7ECD;Image&#x7684;&#x539F;&#x7406;&#x53CA;&#x56FE;&#x7247;&#x7F13;&#x5B58;&#x673A;&#x5236;&#xFF0C;&#x4E0B;&#x9762;&#x6211;&#x4EEC;&#x5148;&#x770B;&#x770B;<code>ImageProvider</code> &#x7C7B;&#x3002;</p>
<h2 id="1451-imageprovider">14.5.1 ImageProvider</h2>
<p>&#x6211;&#x4EEC;&#x5DF2;&#x7ECF;&#x77E5;&#x9053;<code>Image</code> &#x7EC4;&#x4EF6;&#x7684;<code>image</code> &#x53C2;&#x6570;&#x662F;&#x4E00;&#x4E2A;&#x5FC5;&#x9009;&#x53C2;&#x6570;&#xFF0C;&#x5B83;&#x662F;<code>ImageProvider</code>&#x7C7B;&#x578B;&#x3002;&#x4E0B;&#x9762;&#x6211;&#x4EEC;&#x4FBF;&#x8BE6;&#x7EC6;&#x4ECB;&#x7ECD;&#x4E00;&#x4E0B;<code>ImageProvider</code>&#xFF0C;<code>ImageProvider</code>&#x662F;&#x4E00;&#x4E2A;&#x62BD;&#x8C61;&#x7C7B;&#xFF0C;&#x5B9A;&#x4E49;&#x4E86;&#x56FE;&#x7247;&#x6570;&#x636E;&#x83B7;&#x53D6;&#x548C;&#x52A0;&#x8F7D;&#x7684;&#x76F8;&#x5173;&#x63A5;&#x53E3;&#x3002;&#x5B83;&#x7684;&#x4E3B;&#x8981;&#x804C;&#x8D23;&#x6709;&#x4E24;&#x4E2A;&#xFF1A;</p>
<ol>
<li>&#x63D0;&#x4F9B;&#x56FE;&#x7247;&#x6570;&#x636E;&#x6E90;</li>
<li>&#x7F13;&#x5B58;&#x56FE;&#x7247;</li>
</ol>
<p>&#x6211;&#x4EEC;&#x770B;&#x770B;<code>ImageProvider</code>&#x62BD;&#x8C61;&#x7C7B;&#x7684;&#x8BE6;&#x7EC6;&#x5B9A;&#x4E49;&#xFF1A;</p>
<pre class="language-"><code class="lang-dart"><span class="token keyword">abstract</span> <span class="token keyword">class</span> <span class="token class-name">ImageProvider</span><span class="token operator">&lt;</span>T<span class="token operator">&gt;</span> <span class="token punctuation">{</span>

  ImageStream <span class="token function">resolve</span><span class="token punctuation">(</span>ImageConfiguration configuration<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token comment">// &#x5B9E;&#x73B0;&#x4EE3;&#x7801;&#x7701;&#x7565;</span>
  <span class="token punctuation">}</span>
  Future<span class="token operator">&lt;</span>bool<span class="token operator">&gt;</span> <span class="token function">evict</span><span class="token punctuation">(</span><span class="token punctuation">{</span> ImageCache cache<span class="token punctuation">,</span>
                      ImageConfiguration configuration <span class="token operator">=</span> ImageConfiguration<span class="token punctuation">.</span>empty <span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token keyword">async</span> <span class="token punctuation">{</span>
    <span class="token comment">// &#x5B9E;&#x73B0;&#x4EE3;&#x7801;&#x7701;&#x7565;</span>
  <span class="token punctuation">}</span>

  Future<span class="token operator">&lt;</span>T<span class="token operator">&gt;</span> <span class="token function">obtainKey</span><span class="token punctuation">(</span>ImageConfiguration configuration<span class="token punctuation">)</span><span class="token punctuation">;</span> 
  <span class="token metadata symbol">@protected</span>
  ImageStreamCompleter <span class="token function">load</span><span class="token punctuation">(</span>T key<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// &#x9700;&#x5B50;&#x7C7B;&#x5B9E;&#x73B0;</span>
<span class="token punctuation">}</span>
</code></pre>
<h4 id="loadt-key&#x65B9;&#x6CD5;"><code>load(T key)</code>&#x65B9;&#x6CD5;</h4>
<p>&#x52A0;&#x8F7D;&#x56FE;&#x7247;&#x6570;&#x636E;&#x6E90;&#x7684;&#x63A5;&#x53E3;&#xFF0C;&#x4E0D;&#x540C;&#x7684;&#x6570;&#x636E;&#x6E90;&#x7684;&#x52A0;&#x8F7D;&#x65B9;&#x6CD5;&#x4E0D;&#x540C;&#xFF0C;&#x6BCF;&#x4E2A;<code>ImageProvider</code>&#x7684;&#x5B50;&#x7C7B;&#x5FC5;&#x987B;&#x5B9E;&#x73B0;&#x5B83;&#x3002;&#x6BD4;&#x5982;<code>NetworkImage</code>&#x7C7B;&#x548C;<code>AssetImage</code>&#x7C7B;&#xFF0C;&#x5B83;&#x4EEC;&#x90FD;&#x662F;<code>ImageProvider</code>&#x7684;&#x5B50;&#x7C7B;&#xFF0C;&#x4F46;&#x5B83;&#x4EEC;&#x9700;&#x8981;&#x4ECE;&#x4E0D;&#x540C;&#x7684;&#x6570;&#x636E;&#x6E90;&#x6765;&#x52A0;&#x8F7D;&#x56FE;&#x7247;&#x6570;&#x636E;&#xFF1A;<code>NetworkImage</code>&#x662F;&#x4ECE;&#x7F51;&#x7EDC;&#x6765;&#x52A0;&#x8F7D;&#x56FE;&#x7247;&#x6570;&#x636E;&#xFF0C;&#x800C;<code>AssetImage</code>&#x5219;&#x662F;&#x4ECE;&#x6700;&#x7EC8;&#x7684;&#x5E94;&#x7528;&#x5305;&#x91CC;&#x6765;&#x52A0;&#x8F7D;&#xFF08;&#x52A0;&#x8F7D;&#x6253;&#x5230;&#x5E94;&#x7528;&#x5B89;&#x88C5;&#x5305;&#x91CC;&#x7684;&#x8D44;&#x6E90;&#x56FE;&#x7247;&#xFF09;&#x3002; &#x6211;&#x4EEC;&#x4EE5;<code>NetworkImage</code>&#x4E3A;&#x4F8B;&#xFF0C;&#x770B;&#x770B;&#x5176;load&#x65B9;&#x6CD5;&#x7684;&#x5B9E;&#x73B0;&#xFF1A;</p>
<pre class="language-"><code class="lang-dart">
<span class="token metadata symbol">@override</span>
ImageStreamCompleter <span class="token function">load</span><span class="token punctuation">(</span>image_provider<span class="token punctuation">.</span>NetworkImage key<span class="token punctuation">)</span> <span class="token punctuation">{</span>

  <span class="token keyword">final</span> StreamController<span class="token operator">&lt;</span>ImageChunkEvent<span class="token operator">&gt;</span> chunkEvents <span class="token operator">=</span> StreamController<span class="token operator">&lt;</span>ImageChunkEvent<span class="token operator">&gt;</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

  <span class="token keyword">return</span> <span class="token function">MultiFrameImageStreamCompleter</span><span class="token punctuation">(</span>
    codec<span class="token punctuation">:</span> <span class="token function">_loadAsync</span><span class="token punctuation">(</span>key<span class="token punctuation">,</span> chunkEvents<span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token comment">//&#x8C03;&#x7528;</span>
    chunkEvents<span class="token punctuation">:</span> chunkEvents<span class="token punctuation">.</span>stream<span class="token punctuation">,</span>
    scale<span class="token punctuation">:</span> key<span class="token punctuation">.</span>scale<span class="token punctuation">,</span>
    <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> <span class="token comment">//&#x7701;&#x7565;&#x65E0;&#x5173;&#x4EE3;&#x7801;</span>
  <span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x6211;&#x4EEC;&#x770B;&#x5230;&#xFF0C;<code>load</code>&#x65B9;&#x6CD5;&#x7684;&#x8FD4;&#x56DE;&#x503C;&#x7C7B;&#x578B;&#x662F;<code>ImageStreamCompleter</code> &#xFF0C;&#x5B83;&#x662F;&#x4E00;&#x4E2A;&#x62BD;&#x8C61;&#x7C7B;&#xFF0C;&#x5B9A;&#x4E49;&#x4E86;&#x7BA1;&#x7406;&#x56FE;&#x7247;&#x52A0;&#x8F7D;&#x8FC7;&#x7A0B;&#x7684;&#x4E00;&#x4E9B;&#x63A5;&#x53E3;&#xFF0C;<code>Image</code> Widget&#x4E2D;&#x6B63;&#x662F;&#x901A;&#x8FC7;&#x5B83;&#x6765;&#x76D1;&#x542C;&#x56FE;&#x7247;&#x52A0;&#x8F7D;&#x72B6;&#x6001;&#x7684;&#xFF08;&#x6211;&#x4EEC;&#x5C06;&#x5728;&#x4E0B;&#x9762;&#x4ECB;&#x7ECD;<code>Image</code> &#x539F;&#x7406;&#x65F6;&#x8BE6;&#x7EC6;&#x4ECB;&#x7ECD;&#xFF09;&#x3002;</p>
<p><code>MultiFrameImageStreamCompleter</code> &#x662F; <code>ImageStreamCompleter</code>&#x7684;&#x4E00;&#x4E2A;&#x5B50;&#x7C7B;&#xFF0C;&#x662F;flutter sdk&#x9884;&#x7F6E;&#x7684;&#x7C7B;&#xFF0C;&#x901A;&#x8FC7;&#x8BE5;&#x7C7B;&#xFF0C;&#x6211;&#x4EEC;&#x4EE5;&#x65B9;&#x4FBF;&#x3001;&#x8F7B;&#x677E;&#x5730;&#x521B;&#x5EFA;&#x51FA;&#x4E00;&#x4E2A;<code>ImageStreamCompleter</code>&#x5B9E;&#x4F8B;&#x6765;&#x505A;&#x4E3A;<code>load</code>&#x65B9;&#x6CD5;&#x7684;&#x8FD4;&#x56DE;&#x503C;&#x3002;</p>
<p>&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x770B;&#x5230;&#xFF0C;<code>MultiFrameImageStreamCompleter</code> &#x9700;&#x8981;&#x4E00;&#x4E2A;<code>codec</code>&#x53C2;&#x6570;&#xFF0C;&#x8BE5;&#x53C2;&#x6570;&#x7C7B;&#x578B;&#x4E3A;<code>Future<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>ui.Codec</span><span class="token punctuation">&gt;</span></span></code>&#x3002;<code>Codec</code> &#x662F;&#x5904;&#x7406;&#x56FE;&#x7247;&#x7F16;&#x89E3;&#x7801;&#x7684;&#x7C7B;&#x7684;&#x4E00;&#x4E2A;handler&#xFF0C;&#x5B9E;&#x9645;&#x4E0A;&#xFF0C;&#x5B83;&#x53EA;&#x662F;&#x4E00;&#x4E2A;flutter engine API &#x7684;&#x5305;&#x88C5;&#x7C7B;&#xFF0C;&#x4E5F;&#x5C31;&#x662F;&#x8BF4;&#x56FE;&#x7247;&#x7684;&#x7F16;&#x89E3;&#x7801;&#x903B;&#x8F91;&#x4E0D;&#x662F;&#x5728;Dart &#x4EE3;&#x7801;&#x90E8;&#x5206;&#x5B9E;&#x73B0;&#xFF0C;&#x800C;&#x662F;&#x5728;flutter engine&#x4E2D;&#x5B9E;&#x73B0;&#x7684;&#x3002;<code>Codec</code>&#x7C7B;&#x90E8;&#x5206;&#x5B9A;&#x4E49;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre class="language-"><code class="lang-dart"><span class="token metadata symbol">@pragma</span><span class="token punctuation">(</span><span class="token string">&apos;vm:entry-point&apos;</span><span class="token punctuation">)</span>
<span class="token keyword">class</span> <span class="token class-name">Codec</span> <span class="token keyword">extends</span> <span class="token class-name">NativeFieldWrapperClass2</span> <span class="token punctuation">{</span>
  <span class="token comment">// &#x6B64;&#x7C7B;&#x7531;flutter engine&#x521B;&#x5EFA;&#xFF0C;&#x4E0D;&#x5E94;&#x8BE5;&#x624B;&#x52A8;&#x5B9E;&#x4F8B;&#x5316;&#x6B64;&#x7C7B;&#x6216;&#x76F4;&#x63A5;&#x7EE7;&#x627F;&#x6B64;&#x7C7B;&#x3002;</span>
  <span class="token metadata symbol">@pragma</span><span class="token punctuation">(</span><span class="token string">&apos;vm:entry-point&apos;</span><span class="token punctuation">)</span>
  Codec<span class="token punctuation">.</span><span class="token function">_</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

  <span class="token comment">/// &#x56FE;&#x7247;&#x4E2D;&#x7684;&#x5E27;&#x6570;(&#x52A8;&#x6001;&#x56FE;&#x4F1A;&#x6709;&#x591A;&#x5E27;)</span>
  int <span class="token keyword">get</span> frameCount native <span class="token string">&apos;Codec_frameCount&apos;</span><span class="token punctuation">;</span>

  <span class="token comment">/// &#x52A8;&#x753B;&#x91CD;&#x590D;&#x7684;&#x6B21;&#x6570;</span>
  <span class="token comment">/// * 0 &#x8868;&#x793A;&#x53EA;&#x6267;&#x884C;&#x4E00;&#x6B21;</span>
  <span class="token comment">/// * -1 &#x8868;&#x793A;&#x5FAA;&#x73AF;&#x6267;&#x884C;</span>
  int <span class="token keyword">get</span> repetitionCount native <span class="token string">&apos;Codec_repetitionCount&apos;</span><span class="token punctuation">;</span>

  <span class="token comment">/// &#x83B7;&#x53D6;&#x4E0B;&#x4E00;&#x4E2A;&#x52A8;&#x753B;&#x5E27;</span>
  Future<span class="token operator">&lt;</span>FrameInfo<span class="token operator">&gt;</span> <span class="token function">getNextFrame</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token function">_futurize</span><span class="token punctuation">(</span>_getNextFrame<span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>

  String <span class="token function">_getNextFrame</span><span class="token punctuation">(</span>_Callback<span class="token operator">&lt;</span>FrameInfo<span class="token operator">&gt;</span> callback<span class="token punctuation">)</span> native <span class="token string">&apos;Codec_getNextFrame&apos;</span><span class="token punctuation">;</span>
</code></pre>
<p>&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x770B;&#x5230;<code>Codec</code>&#x6700;&#x7EC8;&#x7684;&#x7ED3;&#x679C;&#x662F;&#x4E00;&#x4E2A;&#x6216;&#x591A;&#x4E2A;&#xFF08;&#x52A8;&#x56FE;&#xFF09;&#x5E27;&#xFF0C;&#x800C;&#x8FD9;&#x4E9B;&#x5E27;&#x6700;&#x7EC8;&#x4F1A;&#x7ED8;&#x5236;&#x5230;&#x5C4F;&#x5E55;&#x4E0A;&#x3002;</p>
<p><code>MultiFrameImageStreamCompleter &#x7684;</code> <code>codec</code>&#x53C2;&#x6570;&#x503C;&#x4E3A;<code>_loadAsync</code>&#x65B9;&#x6CD5;&#x7684;&#x8FD4;&#x56DE;&#x503C;&#xFF0C;&#x6211;&#x4EEC;&#x7EE7;&#x7EED;&#x770B;<code>_loadAsync</code>&#x65B9;&#x6CD5;&#x7684;&#x5B9E;&#x73B0;&#xFF1A;</p>
<pre class="language-"><code class="lang-dart">
 Future<span class="token operator">&lt;</span>ui<span class="token punctuation">.</span>Codec<span class="token operator">&gt;</span> <span class="token function">_loadAsync</span><span class="token punctuation">(</span>
    NetworkImage key<span class="token punctuation">,</span>
    StreamController<span class="token operator">&lt;</span>ImageChunkEvent<span class="token operator">&gt;</span> chunkEvents<span class="token punctuation">,</span>
  <span class="token punctuation">)</span> <span class="token keyword">async</span> <span class="token punctuation">{</span>
    <span class="token keyword">try</span> <span class="token punctuation">{</span>
      <span class="token comment">//&#x4E0B;&#x8F7D;&#x56FE;&#x7247;</span>
      <span class="token keyword">final</span> Uri resolved <span class="token operator">=</span> Uri<span class="token punctuation">.</span>base<span class="token punctuation">.</span><span class="token function">resolve</span><span class="token punctuation">(</span>key<span class="token punctuation">.</span>url<span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token keyword">final</span> HttpClientRequest request <span class="token operator">=</span> <span class="token keyword">await</span> _httpClient<span class="token punctuation">.</span><span class="token function">getUrl</span><span class="token punctuation">(</span>resolved<span class="token punctuation">)</span><span class="token punctuation">;</span>
      headers<span class="token operator">?</span><span class="token punctuation">.</span><span class="token function">forEach</span><span class="token punctuation">(</span><span class="token punctuation">(</span>String name<span class="token punctuation">,</span> String value<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        request<span class="token punctuation">.</span>headers<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>name<span class="token punctuation">,</span> value<span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token keyword">final</span> HttpClientResponse response <span class="token operator">=</span> <span class="token keyword">await</span> request<span class="token punctuation">.</span><span class="token function">close</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token keyword">if</span> <span class="token punctuation">(</span>response<span class="token punctuation">.</span>statusCode <span class="token operator">!=</span> HttpStatus<span class="token punctuation">.</span>ok<span class="token punctuation">)</span>
        <span class="token keyword">throw</span> <span class="token function">Exception</span><span class="token punctuation">(</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token comment">// &#x63A5;&#x6536;&#x56FE;&#x7247;&#x6570;&#x636E; </span>
      <span class="token keyword">final</span> Uint8List bytes <span class="token operator">=</span> <span class="token keyword">await</span> <span class="token function">consolidateHttpClientResponseBytes</span><span class="token punctuation">(</span>
        response<span class="token punctuation">,</span>
        onBytesReceived<span class="token punctuation">:</span> <span class="token punctuation">(</span>int cumulative<span class="token punctuation">,</span> int total<span class="token punctuation">)</span> <span class="token punctuation">{</span>
          chunkEvents<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token function">ImageChunkEvent</span><span class="token punctuation">(</span>
            cumulativeBytesLoaded<span class="token punctuation">:</span> cumulative<span class="token punctuation">,</span>
            expectedTotalBytes<span class="token punctuation">:</span> total<span class="token punctuation">,</span>
          <span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span><span class="token punctuation">,</span>
      <span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token keyword">if</span> <span class="token punctuation">(</span>bytes<span class="token punctuation">.</span>lengthInBytes <span class="token operator">==</span> <span class="token number">0</span><span class="token punctuation">)</span>
        <span class="token keyword">throw</span> <span class="token function">Exception</span><span class="token punctuation">(</span><span class="token string">&apos;NetworkImage is an empty file: $resolved&apos;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token comment">// &#x5BF9;&#x56FE;&#x7247;&#x6570;&#x636E;&#x8FDB;&#x884C;&#x89E3;&#x7801;</span>
      <span class="token keyword">return</span> PaintingBinding<span class="token punctuation">.</span>instance<span class="token punctuation">.</span><span class="token function">instantiateImageCodec</span><span class="token punctuation">(</span>bytes<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span> <span class="token keyword">finally</span> <span class="token punctuation">{</span>
      chunkEvents<span class="token punctuation">.</span><span class="token function">close</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
</code></pre>
<p>&#x53EF;&#x4EE5;&#x770B;&#x5230;<code>_loadAsync</code>&#x65B9;&#x6CD5;&#x4E3B;&#x8981;&#x505A;&#x4E86;&#x4E24;&#x4EF6;&#x4E8B;&#xFF1A;</p>
<ol>
<li>&#x4E0B;&#x8F7D;&#x56FE;&#x7247;&#x3002;</li>
<li>&#x5BF9;&#x4E0B;&#x8F7D;&#x7684;&#x56FE;&#x7247;&#x6570;&#x636E;&#x8FDB;&#x884C;&#x89E3;&#x7801;&#x3002;</li>
</ol>
<p>&#x4E0B;&#x8F7D;&#x903B;&#x8F91;&#x6BD4;&#x8F83;&#x7B80;&#x5355;&#xFF1A;&#x901A;&#x8FC7;<code>HttpClient</code>&#x4ECE;&#x7F51;&#x4E0A;&#x4E0B;&#x8F7D;&#x56FE;&#x7247;&#xFF0C;&#x53E6;&#x5916;&#x4E0B;&#x8F7D;&#x8BF7;&#x6C42;&#x4F1A;&#x8BBE;&#x7F6E;&#x4E00;&#x4E9B;&#x81EA;&#x5B9A;&#x4E49;&#x7684;header&#xFF0C;&#x5F00;&#x53D1;&#x8005;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;<code>NetworkImage</code>&#x7684;<code>headers</code>&#x547D;&#x540D;&#x53C2;&#x6570;&#x6765;&#x4F20;&#x9012;&#x3002;</p>
<p>&#x5728;&#x56FE;&#x7247;&#x4E0B;&#x8F7D;&#x5B8C;&#x6210;&#x540E;&#x8C03;&#x7528;&#x4E86;<code>PaintingBinding.instance.instantiateImageCodec(bytes)</code>&#x5BF9;&#x56FE;&#x7247;&#x8FDB;&#x884C;&#x89E3;&#x7801;&#xFF0C;&#x503C;&#x5F97;&#x6CE8;&#x610F;&#x7684;&#x662F;<code>instantiateImageCodec(...)</code>&#x4E5F;&#x662F;&#x4E00;&#x4E2A;Native API&#x7684;&#x5305;&#x88C5;&#xFF0C;&#x5B9E;&#x9645;&#x4E0A;&#x4F1A;&#x8C03;&#x7528;Flutter engine&#x7684;<code>instantiateImageCodec</code>&#x65B9;&#x6CD5;&#xFF0C;&#x6E90;&#x7801;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre class="language-"><code class="lang-dart">String <span class="token function">_instantiateImageCodec</span><span class="token punctuation">(</span>Uint8List list<span class="token punctuation">,</span> _Callback<span class="token operator">&lt;</span>Codec<span class="token operator">&gt;</span> callback<span class="token punctuation">,</span> _ImageInfo imageInfo<span class="token punctuation">,</span> int targetWidth<span class="token punctuation">,</span> int targetHeight<span class="token punctuation">)</span>
  native <span class="token string">&apos;instantiateImageCodec&apos;</span><span class="token punctuation">;</span>
</code></pre>
<h4 id="obtainkeyimageconfiguration&#x65B9;&#x6CD5;"><code>obtainKey(ImageConfiguration)</code>&#x65B9;&#x6CD5;</h4>
<p>&#x8BE5;&#x63A5;&#x53E3;&#x4E3B;&#x8981;&#x662F;&#x4E3A;&#x4E86;&#x914D;&#x5408;&#x5B9E;&#x73B0;&#x56FE;&#x7247;&#x7F13;&#x5B58;&#xFF0C;<code>ImageProvider</code>&#x4ECE;&#x6570;&#x636E;&#x6E90;&#x52A0;&#x8F7D;&#x5B8C;&#x6570;&#x636E;&#x540E;&#xFF0C;&#x4F1A;&#x5728;&#x5168;&#x5C40;&#x7684;<code>ImageCache</code>&#x4E2D;&#x7F13;&#x5B58;&#x56FE;&#x7247;&#x6570;&#x636E;&#xFF0C;&#x800C;&#x56FE;&#x7247;&#x6570;&#x636E;&#x7F13;&#x5B58;&#x662F;&#x4E00;&#x4E2A;Map&#xFF0C;&#x800C;Map&#x7684;key&#x4FBF;&#x662F;&#x8C03;&#x7528;&#x6B64;&#x65B9;&#x6CD5;&#x7684;&#x8FD4;&#x56DE;&#x503C;&#xFF0C;&#x4E0D;&#x540C;&#x7684;key&#x4EE3;&#x8868;&#x4E0D;&#x540C;&#x7684;&#x56FE;&#x7247;&#x6570;&#x636E;&#x7F13;&#x5B58;&#x3002;</p>
<h4 id="resolveimageconfiguration-&#x65B9;&#x6CD5;"><code>resolve(ImageConfiguration)</code> &#x65B9;&#x6CD5;</h4>
<p><code>resolve</code>&#x65B9;&#x6CD5;&#x662F;<code>ImageProvider</code>&#x7684;&#x66B4;&#x9732;&#x7684;&#x7ED9;<code>Image</code>&#x7684;&#x4E3B;&#x5165;&#x53E3;&#x65B9;&#x6CD5;&#xFF0C;&#x5B83;&#x63A5;&#x53D7;&#x4E00;&#x4E2A;<code>ImageConfiguration</code>&#x53C2;&#x6570;&#xFF0C;&#x8FD4;&#x56DE;<code>ImageStream</code>&#xFF0C;&#x5373;&#x56FE;&#x7247;&#x6570;&#x636E;&#x6D41;&#x3002;&#x6211;&#x4EEC;&#x91CD;&#x70B9;&#x770B;&#x4E00;&#x4E0B;<code>resolve</code>&#x6267;&#x884C;&#x6D41;&#x7A0B;&#xFF1A;</p>
<pre class="language-"><code class="lang-dart">ImageStream <span class="token function">resolve</span><span class="token punctuation">(</span>ImageConfiguration configuration<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> <span class="token comment">//&#x7701;&#x7565;&#x65E0;&#x5173;&#x4EE3;&#x7801;</span>
  <span class="token keyword">final</span> ImageStream stream <span class="token operator">=</span> <span class="token function">ImageStream</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  T obtainedKey<span class="token punctuation">;</span> <span class="token comment">//</span>
  <span class="token comment">//&#x5B9A;&#x4E49;&#x9519;&#x8BEF;&#x5904;&#x7406;&#x51FD;&#x6570;</span>
  Future<span class="token operator">&lt;</span><span class="token keyword">void</span><span class="token operator">&gt;</span> <span class="token function">handleError</span><span class="token punctuation">(</span><span class="token keyword">dynamic</span> exception<span class="token punctuation">,</span> StackTrace stack<span class="token punctuation">)</span> <span class="token keyword">async</span> <span class="token punctuation">{</span>
    <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> <span class="token comment">//&#x7701;&#x7565;&#x65E0;&#x5173;&#x4EE3;&#x7801;</span>
    stream<span class="token punctuation">.</span><span class="token function">setCompleter</span><span class="token punctuation">(</span>imageCompleter<span class="token punctuation">)</span><span class="token punctuation">;</span>
    imageCompleter<span class="token punctuation">.</span><span class="token function">setError</span><span class="token punctuation">(</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>

  <span class="token comment">// &#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x65B0;Zone&#xFF0C;&#x4E3B;&#x8981;&#x662F;&#x4E3A;&#x4E86;&#x5F53;&#x53D1;&#x751F;&#x9519;&#x8BEF;&#x65F6;&#x4E0D;&#x4F1A;&#x5E72;&#x6270;MainZone</span>
  <span class="token keyword">final</span> Zone dangerZone <span class="token operator">=</span> Zone<span class="token punctuation">.</span>current<span class="token punctuation">.</span><span class="token function">fork</span><span class="token punctuation">(</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

  dangerZone<span class="token punctuation">.</span><span class="token function">runGuarded</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    Future<span class="token operator">&lt;</span>T<span class="token operator">&gt;</span> key<span class="token punctuation">;</span>
    <span class="token comment">// &#x5148;&#x9A8C;&#x8BC1;&#x662F;&#x5426;&#x5DF2;&#x7ECF;&#x6709;&#x7F13;&#x5B58;</span>
    <span class="token keyword">try</span> <span class="token punctuation">{</span>
      <span class="token comment">// &#x751F;&#x6210;&#x7F13;&#x5B58;key&#xFF0C;&#x540E;&#x9762;&#x4F1A;&#x6839;&#x636E;&#x6B64;key&#x6765;&#x68C0;&#x6D4B;&#x662F;&#x5426;&#x6709;&#x7F13;&#x5B58;</span>
      key <span class="token operator">=</span> <span class="token function">obtainKey</span><span class="token punctuation">(</span>configuration<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span> <span class="token keyword">catch</span> <span class="token punctuation">(</span>error<span class="token punctuation">,</span> stackTrace<span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token function">handleError</span><span class="token punctuation">(</span>error<span class="token punctuation">,</span> stackTrace<span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token keyword">return</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    key<span class="token punctuation">.</span>then<span class="token operator">&lt;</span><span class="token keyword">void</span><span class="token operator">&gt;</span><span class="token punctuation">(</span><span class="token punctuation">(</span>T key<span class="token punctuation">)</span> <span class="token punctuation">{</span>
      obtainedKey <span class="token operator">=</span> key<span class="token punctuation">;</span>
      <span class="token comment">// &#x7F13;&#x5B58;&#x7684;&#x5904;&#x7406;&#x903B;&#x8F91;&#x5728;&#x8FD9;&#x91CC;&#xFF0C;&#x8BB0;&#x4E3A;A&#xFF0C;&#x4E0B;&#x9762;&#x8BE6;&#x7EC6;&#x4ECB;&#x7ECD;</span>
      <span class="token keyword">final</span> ImageStreamCompleter completer <span class="token operator">=</span> PaintingBinding<span class="token punctuation">.</span>instance
          <span class="token punctuation">.</span>imageCache<span class="token punctuation">.</span><span class="token function">putIfAbsent</span><span class="token punctuation">(</span>key<span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">&gt;</span> <span class="token function">load</span><span class="token punctuation">(</span>key<span class="token punctuation">)</span><span class="token punctuation">,</span> onError<span class="token punctuation">:</span> handleError<span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token keyword">if</span> <span class="token punctuation">(</span>completer <span class="token operator">!=</span> <span class="token keyword">null</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        stream<span class="token punctuation">.</span><span class="token function">setCompleter</span><span class="token punctuation">(</span>completer<span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token punctuation">}</span>
    <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">catchError</span><span class="token punctuation">(</span>handleError<span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token keyword">return</span> stream<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
<p><code>ImageConfiguration</code>  &#x5305;&#x542B;&#x56FE;&#x7247;&#x548C;&#x8BBE;&#x5907;&#x7684;&#x76F8;&#x5173;&#x4FE1;&#x606F;&#xFF0C;&#x5982;&#x56FE;&#x7247;&#x7684;&#x5927;&#x5C0F;&#x3001;&#x6240;&#x5728;&#x7684;<code>AssetBundle</code>(&#x53EA;&#x6709;&#x6253;&#x5230;&#x5B89;&#x88C5;&#x5305;&#x7684;&#x56FE;&#x7247;&#x5B58;&#x5728;)&#x4EE5;&#x53CA;&#x5F53;&#x524D;&#x7684;&#x8BBE;&#x5907;&#x5E73;&#x53F0;&#x3001;devicePixelRatio&#xFF08;&#x8BBE;&#x5907;&#x50CF;&#x7D20;&#x6BD4;&#x7B49;&#xFF09;&#x3002;Flutter SDK&#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x4E2A;&#x4FBF;&#x6377;&#x51FD;&#x6570;<code>createLocalImageConfiguration</code>&#x6765;&#x521B;&#x5EFA;<code>ImageConfiguration</code>  &#x5BF9;&#x8C61;&#xFF1A;</p>
<pre class="language-"><code class="lang-dart">ImageConfiguration <span class="token function">createLocalImageConfiguration</span><span class="token punctuation">(</span>BuildContext context<span class="token punctuation">,</span> <span class="token punctuation">{</span> Size size <span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> <span class="token function">ImageConfiguration</span><span class="token punctuation">(</span>
    bundle<span class="token punctuation">:</span> DefaultAssetBundle<span class="token punctuation">.</span><span class="token function">of</span><span class="token punctuation">(</span>context<span class="token punctuation">)</span><span class="token punctuation">,</span>
    devicePixelRatio<span class="token punctuation">:</span> MediaQuery<span class="token punctuation">.</span><span class="token function">of</span><span class="token punctuation">(</span>context<span class="token punctuation">,</span> nullOk<span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">)</span><span class="token operator">?</span><span class="token punctuation">.</span>devicePixelRatio <span class="token operator">?</span><span class="token operator">?</span> <span class="token number">1.0</span><span class="token punctuation">,</span>
    locale<span class="token punctuation">:</span> Localizations<span class="token punctuation">.</span><span class="token function">localeOf</span><span class="token punctuation">(</span>context<span class="token punctuation">,</span> nullOk<span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
    textDirection<span class="token punctuation">:</span> Directionality<span class="token punctuation">.</span><span class="token function">of</span><span class="token punctuation">(</span>context<span class="token punctuation">)</span><span class="token punctuation">,</span>
    size<span class="token punctuation">:</span> size<span class="token punctuation">,</span>
    platform<span class="token punctuation">:</span> defaultTargetPlatform<span class="token punctuation">,</span>
  <span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x53D1;&#x73B0;&#x8FD9;&#x4E9B;&#x4FE1;&#x606F;&#x57FA;&#x672C;&#x90FD;&#x662F;&#x901A;&#x8FC7;<code>Context</code>&#x6765;&#x83B7;&#x53D6;&#x3002;</p>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;A&#x5904;&#x5C31;&#x662F;&#x5904;&#x7406;&#x7F13;&#x5B58;&#x7684;&#x4E3B;&#x8981;&#x4EE3;&#x7801;&#xFF0C;&#x8FD9;&#x91CC;&#x7684;<code>PaintingBinding.instance.imageCache</code> &#x662F; <code>ImageCache</code>&#x7684;&#x4E00;&#x4E2A;&#x5B9E;&#x4F8B;&#xFF0C;&#x5B83;&#x662F;<code>PaintingBinding</code>&#x7684;&#x4E00;&#x4E2A;&#x5C5E;&#x6027;&#xFF0C;&#x800C;Flutter&#x6846;&#x67B6;&#x4E2D;&#x7684;<code>PaintingBinding.instance</code>&#x662F;&#x4E00;&#x4E2A;&#x5355;&#x4F8B;&#xFF0C;<code>imageCache</code>&#x4E8B;&#x5B9E;&#x4E0A;&#x4E5F;&#x662F;&#x4E00;&#x4E2A;&#x5355;&#x4F8B;&#xFF0C;&#x4E5F;&#x5C31;&#x662F;&#x8BF4;&#x56FE;&#x7247;&#x7F13;&#x5B58;&#x662F;&#x5168;&#x5C40;&#x7684;&#xFF0C;&#x7EDF;&#x4E00;&#x7531;<code>PaintingBinding.instance.imageCache</code> &#x6765;&#x7BA1;&#x7406;&#x3002;</p>
<p>&#x4E0B;&#x9762;&#x6211;&#x4EEC;&#x770B;&#x770B;<code>ImageCache</code>&#x7C7B;&#x5B9A;&#x4E49;&#xFF1A;</p>
<pre class="language-"><code class="lang-dart"><span class="token keyword">const</span> int _kDefaultSize <span class="token operator">=</span> <span class="token number">1000</span><span class="token punctuation">;</span>
<span class="token keyword">const</span> int _kDefaultSizeBytes <span class="token operator">=</span> <span class="token number">100</span> <span class="token operator">&lt;&lt;</span> <span class="token number">20</span><span class="token punctuation">;</span> <span class="token comment">// 100 MiB</span>

<span class="token keyword">class</span> <span class="token class-name">ImageCache</span> <span class="token punctuation">{</span>
  <span class="token comment">// &#x6B63;&#x5728;&#x52A0;&#x8F7D;&#x4E2D;&#x7684;&#x56FE;&#x7247;&#x961F;&#x5217;</span>
  <span class="token keyword">final</span> Map<span class="token operator">&lt;</span>Object<span class="token punctuation">,</span> _PendingImage<span class="token operator">&gt;</span> _pendingImages <span class="token operator">=</span> <span class="token operator">&lt;</span>Object<span class="token punctuation">,</span> _PendingImage<span class="token operator">&gt;</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">;</span>
  <span class="token comment">// &#x7F13;&#x5B58;&#x961F;&#x5217;</span>
  <span class="token keyword">final</span> Map<span class="token operator">&lt;</span>Object<span class="token punctuation">,</span> _CachedImage<span class="token operator">&gt;</span> _cache <span class="token operator">=</span> <span class="token operator">&lt;</span>Object<span class="token punctuation">,</span> _CachedImage<span class="token operator">&gt;</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">;</span>

  <span class="token comment">// &#x7F13;&#x5B58;&#x6570;&#x91CF;&#x4E0A;&#x9650;(1000)</span>
  int _maximumSize <span class="token operator">=</span> _kDefaultSize<span class="token punctuation">;</span>
  <span class="token comment">// &#x7F13;&#x5B58;&#x5BB9;&#x91CF;&#x4E0A;&#x9650; (100 MB)</span>
  int _maximumSizeBytes <span class="token operator">=</span> _kDefaultSizeBytes<span class="token punctuation">;</span>

  <span class="token comment">// &#x7F13;&#x5B58;&#x4E0A;&#x9650;&#x8BBE;&#x7F6E;&#x7684;setter</span>
  <span class="token keyword">set</span> <span class="token function">maximumSize</span><span class="token punctuation">(</span>int value<span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">}</span>
  <span class="token keyword">set</span> <span class="token function">maximumSizeBytes</span><span class="token punctuation">(</span>int value<span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">}</span>

  <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> <span class="token comment">// &#x7701;&#x7565;&#x90E8;&#x5206;&#x5B9A;&#x4E49;</span>

  <span class="token comment">// &#x6E05;&#x9664;&#x6240;&#x6709;&#x7F13;&#x5B58;</span>
  <span class="token keyword">void</span> <span class="token function">clear</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token comment">// ...&#x7701;&#x7565;&#x5177;&#x4F53;&#x5B9E;&#x73B0;&#x4EE3;&#x7801;</span>
  <span class="token punctuation">}</span>

  <span class="token comment">// &#x6E05;&#x9664;&#x6307;&#x5B9A;key&#x5BF9;&#x5E94;&#x7684;&#x56FE;&#x7247;&#x7F13;&#x5B58;</span>
  bool <span class="token function">evict</span><span class="token punctuation">(</span>Object key<span class="token punctuation">)</span> <span class="token punctuation">{</span>
   <span class="token comment">// ...&#x7701;&#x7565;&#x5177;&#x4F53;&#x5B9E;&#x73B0;&#x4EE3;&#x7801;</span>
  <span class="token punctuation">}</span>


  ImageStreamCompleter <span class="token function">putIfAbsent</span><span class="token punctuation">(</span>Object key<span class="token punctuation">,</span> ImageStreamCompleter <span class="token function">loader</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">{</span> ImageErrorListener onError <span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">assert</span><span class="token punctuation">(</span>key <span class="token operator">!=</span> <span class="token keyword">null</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">assert</span><span class="token punctuation">(</span>loader <span class="token operator">!=</span> <span class="token keyword">null</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    ImageStreamCompleter result <span class="token operator">=</span> _pendingImages<span class="token punctuation">[</span>key<span class="token punctuation">]</span><span class="token operator">?</span><span class="token punctuation">.</span>completer<span class="token punctuation">;</span>
    <span class="token comment">// &#x56FE;&#x7247;&#x8FD8;&#x672A;&#x52A0;&#x8F7D;&#x6210;&#x529F;&#xFF0C;&#x76F4;&#x63A5;&#x8FD4;&#x56DE;</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span>result <span class="token operator">!=</span> <span class="token keyword">null</span><span class="token punctuation">)</span>
      <span class="token keyword">return</span> result<span class="token punctuation">;</span>

    <span class="token comment">// &#x6709;&#x7F13;&#x5B58;&#xFF0C;&#x7EE7;&#x7EED;&#x5F80;&#x4E0B;&#x8D70;</span>
    <span class="token comment">// &#x5148;&#x79FB;&#x9664;&#x7F13;&#x5B58;&#xFF0C;&#x540E;&#x518D;&#x6DFB;&#x52A0;&#xFF0C;&#x53EF;&#x4EE5;&#x8BA9;&#x6700;&#x65B0;&#x4F7F;&#x7528;&#x8FC7;&#x7684;&#x7F13;&#x5B58;&#x5728;_map&#x4E2D;&#x7684;&#x4F4D;&#x7F6E;&#x66F4;&#x8FD1;&#x4E00;&#x4E9B;&#xFF0C;&#x6E05;&#x7406;&#x65F6;&#x4F1A;LRU&#x6765;&#x6E05;&#x9664;</span>
    <span class="token keyword">final</span> _CachedImage image <span class="token operator">=</span> _cache<span class="token punctuation">.</span><span class="token function">remove</span><span class="token punctuation">(</span>key<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span>image <span class="token operator">!=</span> <span class="token keyword">null</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      _cache<span class="token punctuation">[</span>key<span class="token punctuation">]</span> <span class="token operator">=</span> image<span class="token punctuation">;</span>
      <span class="token keyword">return</span> image<span class="token punctuation">.</span>completer<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">try</span> <span class="token punctuation">{</span>
      result <span class="token operator">=</span> <span class="token function">loader</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span> <span class="token keyword">catch</span> <span class="token punctuation">(</span>error<span class="token punctuation">,</span> stackTrace<span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token keyword">if</span> <span class="token punctuation">(</span>onError <span class="token operator">!=</span> <span class="token keyword">null</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token function">onError</span><span class="token punctuation">(</span>error<span class="token punctuation">,</span> stackTrace<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">return</span> <span class="token keyword">null</span><span class="token punctuation">;</span>
      <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
        <span class="token keyword">rethrow</span><span class="token punctuation">;</span>
      <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">void</span> <span class="token function">listener</span><span class="token punctuation">(</span>ImageInfo info<span class="token punctuation">,</span> bool syncCall<span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token keyword">final</span> int imageSize <span class="token operator">=</span> info<span class="token operator">?</span><span class="token punctuation">.</span>image <span class="token operator">==</span> <span class="token keyword">null</span> <span class="token operator">?</span> <span class="token number">0</span> <span class="token punctuation">:</span> info<span class="token punctuation">.</span>image<span class="token punctuation">.</span>height <span class="token operator">*</span> info<span class="token punctuation">.</span>image<span class="token punctuation">.</span>width <span class="token operator">*</span> <span class="token number">4</span><span class="token punctuation">;</span>
      <span class="token keyword">final</span> _CachedImage image <span class="token operator">=</span> <span class="token function">_CachedImage</span><span class="token punctuation">(</span>result<span class="token punctuation">,</span> imageSize<span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token comment">// &#x4E0B;&#x9762;&#x662F;&#x7F13;&#x5B58;&#x5904;&#x7406;&#x7684;&#x903B;&#x8F91;</span>
      <span class="token keyword">if</span> <span class="token punctuation">(</span>maximumSizeBytes <span class="token operator">&gt;</span> <span class="token number">0</span> <span class="token operator">&amp;&amp;</span> imageSize <span class="token operator">&gt;</span> maximumSizeBytes<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        _maximumSizeBytes <span class="token operator">=</span> imageSize <span class="token operator">+</span> <span class="token number">1000</span><span class="token punctuation">;</span>
      <span class="token punctuation">}</span>
      _currentSizeBytes <span class="token operator">+=</span> imageSize<span class="token punctuation">;</span>
      <span class="token keyword">final</span> _PendingImage pendingImage <span class="token operator">=</span> _pendingImages<span class="token punctuation">.</span><span class="token function">remove</span><span class="token punctuation">(</span>key<span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token keyword">if</span> <span class="token punctuation">(</span>pendingImage <span class="token operator">!=</span> <span class="token keyword">null</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        pendingImage<span class="token punctuation">.</span><span class="token function">removeListener</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token punctuation">}</span>

      _cache<span class="token punctuation">[</span>key<span class="token punctuation">]</span> <span class="token operator">=</span> image<span class="token punctuation">;</span>
      <span class="token function">_checkCacheSize</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span>maximumSize <span class="token operator">&gt;</span> <span class="token number">0</span> <span class="token operator">&amp;&amp;</span> maximumSizeBytes <span class="token operator">&gt;</span> <span class="token number">0</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token keyword">final</span> ImageStreamListener streamListener <span class="token operator">=</span> <span class="token function">ImageStreamListener</span><span class="token punctuation">(</span>listener<span class="token punctuation">)</span><span class="token punctuation">;</span>
      _pendingImages<span class="token punctuation">[</span>key<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token function">_PendingImage</span><span class="token punctuation">(</span>result<span class="token punctuation">,</span> streamListener<span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token comment">// Listener is removed in [_PendingImage.removeListener].</span>
      result<span class="token punctuation">.</span><span class="token function">addListener</span><span class="token punctuation">(</span>streamListener<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">return</span> result<span class="token punctuation">;</span>
  <span class="token punctuation">}</span>

  <span class="token comment">// &#x5F53;&#x7F13;&#x5B58;&#x6570;&#x91CF;&#x8D85;&#x8FC7;&#x6700;&#x5927;&#x503C;&#x6216;&#x7F13;&#x5B58;&#x7684;&#x5927;&#x5C0F;&#x8D85;&#x8FC7;&#x6700;&#x5927;&#x7F13;&#x5B58;&#x5BB9;&#x91CF;&#xFF0C;&#x4F1A;&#x8C03;&#x7528;&#x6B64;&#x65B9;&#x6CD5;&#x6E05;&#x7406;&#x5230;&#x7F13;&#x5B58;&#x4E0A;&#x9650;&#x4EE5;&#x5185;</span>
  <span class="token keyword">void</span> <span class="token function">_checkCacheSize</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
   <span class="token keyword">while</span> <span class="token punctuation">(</span>_currentSizeBytes <span class="token operator">&gt;</span> _maximumSizeBytes <span class="token operator">||</span> _cache<span class="token punctuation">.</span>length <span class="token operator">&gt;</span> _maximumSize<span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token keyword">final</span> Object key <span class="token operator">=</span> _cache<span class="token punctuation">.</span>keys<span class="token punctuation">.</span>first<span class="token punctuation">;</span>
      <span class="token keyword">final</span> _CachedImage image <span class="token operator">=</span> _cache<span class="token punctuation">[</span>key<span class="token punctuation">]</span><span class="token punctuation">;</span>
      _currentSizeBytes <span class="token operator">-=</span> image<span class="token punctuation">.</span>sizeBytes<span class="token punctuation">;</span>
      _cache<span class="token punctuation">.</span><span class="token function">remove</span><span class="token punctuation">(</span>key<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> <span class="token comment">//&#x7701;&#x7565;&#x65E0;&#x5173;&#x4EE3;&#x7801;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x6709;&#x7F13;&#x5B58;&#x5219;&#x4F7F;&#x7528;&#x7F13;&#x5B58;&#xFF0C;&#x6CA1;&#x6709;&#x7F13;&#x5B58;&#x5219;&#x8C03;&#x7528;load&#x65B9;&#x6CD5;&#x52A0;&#x8F7D;&#x56FE;&#x7247;&#xFF0C;&#x52A0;&#x8F7D;&#x6210;&#x529F;&#x540E;:</p>
<ol>
<li>&#x5148;&#x5224;&#x65AD;&#x56FE;&#x7247;&#x6570;&#x636E;&#x6709;&#x6CA1;&#x6709;&#x7F13;&#x5B58;&#xFF0C;&#x5982;&#x679C;&#x6709;&#xFF0C;&#x5219;&#x76F4;&#x63A5;&#x8FD4;&#x56DE;<code>ImageStream</code>&#x3002;</li>
<li>&#x5982;&#x679C;&#x6CA1;&#x6709;&#x7F13;&#x5B58;&#xFF0C;&#x5219;&#x8C03;&#x7528;<code>load(T key)</code>&#x65B9;&#x6CD5;&#x4ECE;&#x6570;&#x636E;&#x6E90;&#x52A0;&#x8F7D;&#x56FE;&#x7247;&#x6570;&#x636E;&#xFF0C;&#x52A0;&#x8F7D;&#x6210;&#x529F;&#x540E;&#x5148;&#x7F13;&#x5B58;&#xFF0C;&#x7136;&#x540E;&#x8FD4;&#x56DE;ImageStream&#x3002;</li>
</ol>
<p>&#x53E6;&#x5916;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x770B;&#x5230;<code>ImageCache</code>&#x7C7B;&#x4E2D;&#x6709;&#x8BBE;&#x7F6E;&#x7F13;&#x5B58;&#x4E0A;&#x9650;&#x7684;setter&#xFF0C;&#x6240;&#x4EE5;&#xFF0C;&#x5982;&#x679C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x81EA;&#x5B9A;&#x4E49;&#x7F13;&#x5B58;&#x4E0A;&#x9650;&#xFF1A;</p>
<pre class="language-"><code class="lang-dart"> PaintingBinding<span class="token punctuation">.</span>instance<span class="token punctuation">.</span>imageCache<span class="token punctuation">.</span>maximumSize<span class="token operator">=</span><span class="token number">2000</span><span class="token punctuation">;</span> <span class="token comment">//&#x6700;&#x591A;2000&#x5F20;</span>
 PaintingBinding<span class="token punctuation">.</span>instance<span class="token punctuation">.</span>imageCache<span class="token punctuation">.</span>maximumSizeBytes <span class="token operator">=</span> <span class="token number">200</span> <span class="token operator">&lt;&lt;</span> <span class="token number">20</span><span class="token punctuation">;</span> <span class="token comment">//&#x6700;&#x5927;200M</span>
</code></pre>
<p>&#x73B0;&#x5728;&#x6211;&#x4EEC;&#x770B;&#x4E00;&#x4E0B;&#x7F13;&#x5B58;&#x7684;key&#xFF0C;&#x56E0;&#x4E3A;Map&#x4E2D;&#x76F8;&#x540C;key&#x7684;&#x503C;&#x4F1A;&#x88AB;&#x8986;&#x76D6;&#xFF0C;&#x4E5F;&#x5C31;&#x662F;&#x8BF4;key&#x662F;&#x56FE;&#x7247;&#x7F13;&#x5B58;&#x7684;&#x4E00;&#x4E2A;&#x552F;&#x4E00;&#x6807;&#x8BC6;&#xFF0C;&#x53EA;&#x8981;&#x662F;&#x4E0D;&#x540C;key&#xFF0C;&#x90A3;&#x4E48;&#x56FE;&#x7247;&#x6570;&#x636E;&#x5C31;&#x4F1A;&#x5206;&#x522B;&#x7F13;&#x5B58;&#xFF08;&#x5373;&#x4F7F;&#x4E8B;&#x5B9E;&#x4E0A;&#x662F;&#x540C;&#x4E00;&#x5F20;&#x56FE;&#x7247;&#xFF09;&#x3002;&#x90A3;&#x4E48;&#x56FE;&#x7247;&#x7684;&#x552F;&#x4E00;&#x6807;&#x8BC6;&#x662F;&#x4EC0;&#x4E48;&#x5462;&#xFF1F;&#x8DDF;&#x8E2A;&#x6E90;&#x7801;&#xFF0C;&#x5F88;&#x5BB9;&#x6613;&#x53D1;&#x73B0;key&#x6B63;&#x662F;<code>ImageProvider.obtainKey()</code>&#x65B9;&#x6CD5;&#x7684;&#x8FD4;&#x56DE;&#x503C;&#xFF0C;&#x800C;&#x6B64;&#x65B9;&#x6CD5;&#x9700;&#x8981;<code>ImageProvider</code>&#x5B50;&#x7C7B;&#x53BB;&#x91CD;&#x5199;&#xFF0C;&#x8FD9;&#x4E5F;&#x5C31;&#x610F;&#x5473;&#x7740;&#x4E0D;&#x540C;&#x7684;<code>ImageProvider</code>&#x5BF9;key&#x7684;&#x5B9A;&#x4E49;&#x903B;&#x8F91;&#x4F1A;&#x4E0D;&#x540C;&#x3002;&#x5176;&#x5B9E;&#x4E5F;&#x5F88;&#x597D;&#x7406;&#x89E3;&#xFF0C;&#x6BD4;&#x5982;&#x5BF9;&#x4E8E;<code>NetworkImage</code>&#xFF0C;&#x5C06;&#x56FE;&#x7247;&#x7684;url&#x4F5C;&#x4E3A;key&#x4F1A;&#x5F88;&#x5408;&#x9002;&#xFF0C;&#x800C;&#x5BF9;&#x4E8E;<code>AssetImage</code>&#xFF0C;&#x5219;&#x5E94;&#x8BE5;&#x5C06;&#x201C;&#x5305;&#x540D;+&#x8DEF;&#x5F84;&#x201D;&#x4F5C;&#x4E3A;&#x552F;&#x4E00;&#x7684;key&#x3002;&#x4E0B;&#x9762;&#x6211;&#x4EEC;&#x4EE5;<code>NetworkImage</code>&#x4E3A;&#x4F8B;&#xFF0C;&#x770B;&#x4E00;&#x4E0B;&#x5B83;&#x7684;<code>obtainKey()</code>&#x5B9E;&#x73B0;&#xFF1A;</p>
<pre class="language-"><code class="lang-dart"><span class="token metadata symbol">@override</span>
Future<span class="token operator">&lt;</span>NetworkImage<span class="token operator">&gt;</span> <span class="token function">obtainKey</span><span class="token punctuation">(</span>image_provider<span class="token punctuation">.</span>ImageConfiguration configuration<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> SynchronousFuture<span class="token operator">&lt;</span>NetworkImage<span class="token operator">&gt;</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x4EE3;&#x7801;&#x5F88;&#x7B80;&#x5355;&#xFF0C;&#x521B;&#x5EFA;&#x4E86;&#x4E00;&#x4E2A;&#x540C;&#x6B65;&#x7684;future&#xFF0C;&#x7136;&#x540E;&#x76F4;&#x63A5;&#x5C06;&#x81EA;&#x8EAB;&#x505A;&#x4E3A;key&#x8FD4;&#x56DE;&#x3002;&#x56E0;&#x4E3A;Map&#x4E2D;&#x5728;&#x5224;&#x65AD;key&#xFF08;&#x6B64;&#x65F6;&#x662F;<code>NetworkImage</code>&#x5BF9;&#x8C61;&#xFF09;&#x662F;&#x5426;&#x76F8;&#x7B49;&#x65F6;&#x4F1A;&#x4F7F;&#x7528;&#x201C;==&#x201D;&#x8FD0;&#x7B97;&#x7B26;&#xFF0C;&#x90A3;&#x4E48;&#x5B9A;&#x4E49;key&#x7684;&#x903B;&#x8F91;&#x5C31;&#x662F;<code>NetworkImage</code>&#x7684;&#x201C;==&#x201D;&#x8FD0;&#x7B97;&#x7B26;&#xFF1A;</p>
<pre class="language-"><code class="lang-dart"><span class="token metadata symbol">@override</span>
bool <span class="token keyword">operator</span> <span class="token operator">==</span><span class="token punctuation">(</span><span class="token keyword">dynamic</span> other<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> <span class="token comment">//&#x7701;&#x7565;&#x65E0;&#x5173;&#x4EE3;&#x7801;</span>
  <span class="token keyword">final</span> NetworkImage typedOther <span class="token operator">=</span> other<span class="token punctuation">;</span>
  <span class="token keyword">return</span> url <span class="token operator">==</span> typedOther<span class="token punctuation">.</span>url
      <span class="token operator">&amp;&amp;</span> scale <span class="token operator">==</span> typedOther<span class="token punctuation">.</span>scale<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x5F88;&#x6E05;&#x6670;&#xFF0C;&#x5BF9;&#x4E8E;&#x7F51;&#x7EDC;&#x56FE;&#x7247;&#x6765;&#x8BF4;&#xFF0C;&#x4F1A;&#x5C06;&#x5176;&#x201C;url+&#x7F29;&#x653E;&#x6BD4;&#x4F8B;&#x201D;&#x4F5C;&#x4E3A;&#x7F13;&#x5B58;&#x7684;key&#x3002;&#x4E5F;&#x5C31;&#x662F;&#x8BF4;<strong>&#x5982;&#x679C;&#x4E24;&#x5F20;&#x56FE;&#x7247;&#x7684;url&#x6216;scale&#x53EA;&#x8981;&#x6709;&#x4E00;&#x4E2A;&#x4E0D;&#x540C;&#xFF0C;&#x4FBF;&#x4F1A;&#x91CD;&#x65B0;&#x4E0B;&#x8F7D;&#x5E76;&#x5206;&#x522B;&#x7F13;&#x5B58;</strong>&#x3002;</p>
<p>&#x53E6;&#x5916;&#xFF0C;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x6CE8;&#x610F;&#x7684;&#x662F;&#xFF0C;&#x56FE;&#x7247;&#x7F13;&#x5B58;&#x662F;&#x5728;&#x5185;&#x5B58;&#x4E2D;&#xFF0C;&#x5E76;&#x6CA1;&#x6709;&#x8FDB;&#x884C;&#x672C;&#x5730;&#x6587;&#x4EF6;&#x6301;&#x4E45;&#x5316;&#x5B58;&#x50A8;&#xFF0C;&#x8FD9;&#x4E5F;&#x662F;&#x4E3A;&#x4EC0;&#x4E48;&#x7F51;&#x7EDC;&#x56FE;&#x7247;&#x5728;&#x5E94;&#x7528;&#x91CD;&#x542F;&#x540E;&#x9700;&#x8981;&#x91CD;&#x65B0;&#x8054;&#x7F51;&#x4E0B;&#x8F7D;&#x7684;&#x539F;&#x56E0;&#x3002;</p>
<p>&#x540C;&#x65F6;&#x4E5F;&#x610F;&#x5473;&#x7740;&#x5728;&#x5E94;&#x7528;&#x751F;&#x547D;&#x5468;&#x671F;&#x5185;&#xFF0C;&#x5982;&#x679C;&#x7F13;&#x5B58;&#x6CA1;&#x6709;&#x8D85;&#x8FC7;&#x4E0A;&#x9650;&#xFF0C;&#x76F8;&#x540C;&#x7684;&#x56FE;&#x7247;&#x53EA;&#x4F1A;&#x88AB;&#x4E0B;&#x8F7D;&#x4E00;&#x6B21;&#x3002;</p>
<h3 id="&#x603B;&#x7ED3;">&#x603B;&#x7ED3;</h3>
<p>&#x4E0A;&#x9762;&#x4E3B;&#x8981;&#x7ED3;&#x5408;&#x6E90;&#x7801;&#xFF0C;&#x63A2;&#x7D22;&#x4E86;<code>ImageProvider</code>&#x7684;&#x4E3B;&#x8981;&#x529F;&#x80FD;&#x548C;&#x539F;&#x7406;&#xFF0C;&#x5982;&#x679C;&#x8981;&#x7528;&#x4E00;&#x53E5;&#x8BDD;&#x6765;&#x603B;&#x7ED3;<code>ImageProvider</code>&#x529F;&#x80FD;&#xFF0C;&#x90A3;&#x4E48;&#x5E94;&#x8BE5;&#x662F;&#xFF1A;&#x52A0;&#x8F7D;&#x56FE;&#x7247;&#x6570;&#x636E;&#x5E76;&#x8FDB;&#x884C;&#x7F13;&#x5B58;&#x3001;&#x89E3;&#x7801;&#x3002;&#x5728;&#x6B64;&#x518D;&#x6B21;&#x63D0;&#x9192;&#x8BFB;&#x8005;&#xFF0C;Flutter&#x7684;&#x6E90;&#x7801;&#x662F;&#x975E;&#x5E38;&#x597D;&#x7684;&#x7B2C;&#x4E00;&#x624B;&#x8D44;&#x6599;&#xFF0C;&#x5EFA;&#x8BAE;&#x8BFB;&#x8005;&#x591A;&#x591A;&#x63A2;&#x7D22;&#xFF0C;&#x53E6;&#x5916;&#xFF0C;&#x5728;&#x9605;&#x8BFB;&#x6E90;&#x7801;&#x5B66;&#x4E60;&#x7684;&#x540C;&#x65F6;&#x4E00;&#x5B9A;&#x8981;&#x6709;&#x603B;&#x7ED3;&#xFF0C;&#x8FD9;&#x6837;&#x624D;&#x4E0D;&#x81F3;&#x4E8E;&#x5728;&#x6E90;&#x7801;&#x4E2D;&#x8FF7;&#x5931;&#x3002;</p>
<h2 id="1452-image&#x7EC4;&#x4EF6;&#x539F;&#x7406;">14.5.2 Image&#x7EC4;&#x4EF6;&#x539F;&#x7406;</h2>
<p>&#x524D;&#x9762;&#x7AE0;&#x8282;&#x4E2D;&#x6211;&#x4EEC;&#x4ECB;&#x7ECD;&#x8FC7;<code>Image</code>&#x7684;&#x57FA;&#x7840;&#x7528;&#x6CD5;&#xFF0C;&#x73B0;&#x5728;&#x6211;&#x4EEC;&#x66F4;&#x6DF1;&#x5165;&#x4E00;&#x4E9B;&#xFF0C;&#x7814;&#x7A76;&#x4E00;&#x4E0B;<code>Image</code>&#x662F;&#x5982;&#x4F55;&#x548C;<code>ImageProvider</code>&#x914D;&#x5408;&#x6765;&#x83B7;&#x53D6;&#x6700;&#x7EC8;&#x89E3;&#x7801;&#x540E;&#x7684;&#x6570;&#x636E;&#xFF0C;&#x7136;&#x540E;&#x53C8;&#x5982;&#x4F55;&#x5C06;&#x56FE;&#x7247;&#x7ED8;&#x5236;&#x5230;&#x5C4F;&#x5E55;&#x4E0A;&#x7684;&#x3002;</p>
<p>&#x672C;&#x8282;&#x6362;&#x4E00;&#x4E2A;&#x601D;&#x8DEF;&#xFF0C;&#x6211;&#x4EEC;&#x5148;&#x4E0D;&#x53BB;&#x76F4;&#x63A5;&#x770B;<code>Image</code>&#x7684;&#x6E90;&#x7801;&#xFF0C;&#x800C;&#x6839;&#x636E;&#x5DF2;&#x7ECF;&#x638C;&#x63E1;&#x7684;&#x77E5;&#x8BC6;&#x6765;&#x5B9E;&#x73B0;&#x4E00;&#x4E2A;&#x7B80;&#x7248;&#x7684;&#x201C;<code>Image</code>&#x7EC4;&#x4EF6;&#x201D; <code>MyImage</code>&#xFF0C;&#x4EE3;&#x7801;&#x5927;&#x81F4;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre class="language-"><code class="lang-dart"><span class="token keyword">class</span> <span class="token class-name">MyImage</span> <span class="token keyword">extends</span> <span class="token class-name">StatefulWidget</span> <span class="token punctuation">{</span>
  <span class="token keyword">const</span> <span class="token function">MyImage</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
    Key key<span class="token punctuation">,</span>
    <span class="token metadata symbol">@required</span> <span class="token keyword">this</span><span class="token punctuation">.</span>imageProvider<span class="token punctuation">,</span>
  <span class="token punctuation">}</span><span class="token punctuation">)</span>
      <span class="token punctuation">:</span> <span class="token keyword">assert</span><span class="token punctuation">(</span>imageProvider <span class="token operator">!=</span> <span class="token keyword">null</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
        <span class="token keyword">super</span><span class="token punctuation">(</span>key<span class="token punctuation">:</span> key<span class="token punctuation">)</span><span class="token punctuation">;</span>

  <span class="token keyword">final</span> ImageProvider imageProvider<span class="token punctuation">;</span>

  <span class="token metadata symbol">@override</span>
  _MyImageState <span class="token function">createState</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">&gt;</span> <span class="token function">_MyImageState</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token keyword">class</span> <span class="token class-name">_MyImageState</span> <span class="token keyword">extends</span> <span class="token class-name">State</span><span class="token operator">&lt;</span>MyImage<span class="token operator">&gt;</span> <span class="token punctuation">{</span>
  ImageStream _imageStream<span class="token punctuation">;</span>
  ImageInfo _imageInfo<span class="token punctuation">;</span>

  <span class="token metadata symbol">@override</span>
  <span class="token keyword">void</span> <span class="token function">didChangeDependencies</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">super</span><span class="token punctuation">.</span><span class="token function">didChangeDependencies</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment">// &#x4F9D;&#x8D56;&#x6539;&#x53D8;&#x65F6;&#xFF0C;&#x56FE;&#x7247;&#x7684;&#x914D;&#x7F6E;&#x4FE1;&#x606F;&#x53EF;&#x80FD;&#x4F1A;&#x53D1;&#x751F;&#x6539;&#x53D8;</span>
    <span class="token function">_getImage</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>

  <span class="token metadata symbol">@override</span>
  <span class="token keyword">void</span> <span class="token function">didUpdateWidget</span><span class="token punctuation">(</span>MyImage oldWidget<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">super</span><span class="token punctuation">.</span><span class="token function">didUpdateWidget</span><span class="token punctuation">(</span>oldWidget<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span>widget<span class="token punctuation">.</span>imageProvider <span class="token operator">!=</span> oldWidget<span class="token punctuation">.</span>imageProvider<span class="token punctuation">)</span>
      <span class="token function">_getImage</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>

  <span class="token keyword">void</span> <span class="token function">_getImage</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">final</span> ImageStream oldImageStream <span class="token operator">=</span> _imageStream<span class="token punctuation">;</span>
    <span class="token comment">// &#x8C03;&#x7528;imageProvider.resolve&#x65B9;&#x6CD5;&#xFF0C;&#x83B7;&#x5F97;ImageStream&#x3002;</span>
    _imageStream <span class="token operator">=</span>
        widget<span class="token punctuation">.</span>imageProvider<span class="token punctuation">.</span><span class="token function">resolve</span><span class="token punctuation">(</span><span class="token function">createLocalImageConfiguration</span><span class="token punctuation">(</span>context<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment">//&#x5224;&#x65AD;&#x65B0;&#x65E7;ImageStream&#x662F;&#x5426;&#x76F8;&#x540C;&#xFF0C;&#x5982;&#x679C;&#x4E0D;&#x540C;&#xFF0C;&#x5219;&#x9700;&#x8981;&#x8C03;&#x6574;&#x6D41;&#x7684;&#x76D1;&#x542C;&#x5668;</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span>_imageStream<span class="token punctuation">.</span>key <span class="token operator">!=</span> oldImageStream<span class="token operator">?</span><span class="token punctuation">.</span>key<span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token keyword">final</span> ImageStreamListener listener <span class="token operator">=</span> <span class="token function">ImageStreamListener</span><span class="token punctuation">(</span>_updateImage<span class="token punctuation">)</span><span class="token punctuation">;</span>
      oldImageStream<span class="token operator">?</span><span class="token punctuation">.</span><span class="token function">removeListener</span><span class="token punctuation">(</span>listener<span class="token punctuation">)</span><span class="token punctuation">;</span>
      _imageStream<span class="token punctuation">.</span><span class="token function">addListener</span><span class="token punctuation">(</span>listener<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>

  <span class="token keyword">void</span> <span class="token function">_updateImage</span><span class="token punctuation">(</span>ImageInfo imageInfo<span class="token punctuation">,</span> bool synchronousCall<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token function">setState</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token comment">// Trigger a build whenever the image changes.</span>
      _imageInfo <span class="token operator">=</span> imageInfo<span class="token punctuation">;</span>
    <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>

  <span class="token metadata symbol">@override</span>
  <span class="token keyword">void</span> <span class="token function">dispose</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    _imageStream<span class="token punctuation">.</span><span class="token function">removeListener</span><span class="token punctuation">(</span><span class="token function">ImageStreamListener</span><span class="token punctuation">(</span>_updateImage<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">super</span><span class="token punctuation">.</span><span class="token function">dispose</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>

  <span class="token metadata symbol">@override</span>
  Widget <span class="token function">build</span><span class="token punctuation">(</span>BuildContext context<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token function">RawImage</span><span class="token punctuation">(</span>
      image<span class="token punctuation">:</span> _imageInfo<span class="token operator">?</span><span class="token punctuation">.</span>image<span class="token punctuation">,</span> <span class="token comment">// this is a dart:ui Image object</span>
      scale<span class="token punctuation">:</span> _imageInfo<span class="token operator">?</span><span class="token punctuation">.</span>scale <span class="token operator">?</span><span class="token operator">?</span> <span class="token number">1.0</span><span class="token punctuation">,</span>
    <span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x6D41;&#x7A0B;&#x5982;&#x4E0B;&#xFF1A;</p>
<ol>
<li>&#x901A;&#x8FC7;<code>imageProvider.resolve</code>&#x65B9;&#x6CD5;&#x53EF;&#x4EE5;&#x5F97;&#x5230;&#x4E00;&#x4E2A;<code>ImageStream</code>&#xFF08;&#x56FE;&#x7247;&#x6570;&#x636E;&#x6D41;&#xFF09;&#xFF0C;&#x7136;&#x540E;&#x76D1;&#x542C;<code>ImageStream</code>&#x7684;&#x53D8;&#x5316;&#x3002;&#x5F53;&#x56FE;&#x7247;&#x6570;&#x636E;&#x6E90;&#x53D1;&#x751F;&#x53D8;&#x5316;&#x65F6;&#xFF0C;<code>ImageStream</code>&#x4F1A;&#x89E6;&#x53D1;&#x76F8;&#x5E94;&#x7684;&#x4E8B;&#x4EF6;&#xFF0C;&#x800C;&#x672C;&#x4F8B;&#x4E2D;&#x6211;&#x4EEC;&#x53EA;&#x8BBE;&#x7F6E;&#x4E86;&#x56FE;&#x7247;&#x6210;&#x529F;&#x7684;&#x76D1;&#x542C;&#x5668;<code>_updateImage</code>&#xFF0C;&#x800C;<code>_updateImage</code>&#x4E2D;&#x53EA;&#x66F4;&#x65B0;&#x4E86;<code>_imageInfo</code>&#x3002;&#x503C;&#x5F97;&#x6CE8;&#x610F;&#x7684;&#x662F;&#xFF0C;&#x5982;&#x679C;&#x662F;&#x9759;&#x6001;&#x56FE;&#xFF0C;<code>ImageStream</code>&#x53EA;&#x4F1A;&#x89E6;&#x53D1;&#x4E00;&#x6B21;&#x65F6;&#x95F4;&#xFF0C;&#x5982;&#x679C;&#x662F;&#x52A8;&#x6001;&#x56FE;&#xFF0C;&#x5219;&#x4F1A;&#x89E6;&#x53D1;&#x591A;&#x6B21;&#x4E8B;&#x4EF6;&#xFF0C;&#x6BCF;&#x4E00;&#x6B21;&#x90FD;&#x4F1A;&#x6709;&#x4E00;&#x4E2A;&#x89E3;&#x7801;&#x540E;&#x7684;&#x56FE;&#x7247;&#x5E27;&#x3002;</li>
<li><code>_imageInfo</code> &#x66F4;&#x65B0;&#x540E;&#x4F1A;rebuild&#xFF0C;&#x6B64;&#x65F6;&#x4F1A;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;<code>RawImage</code> Widget&#x3002;<code>RawImage</code>&#x6700;&#x7EC8;&#x4F1A;&#x901A;&#x8FC7;<code>RenderImage</code>&#x6765;&#x5C06;&#x56FE;&#x7247;&#x7ED8;&#x5236;&#x5728;&#x5C4F;&#x5E55;&#x4E0A;&#x3002;&#x5982;&#x679C;&#x7EE7;&#x7EED;&#x8DDF;&#x8FDB;<code>RenderImage</code>&#x7C7B;&#xFF0C;&#x6211;&#x4EEC;&#x4F1A;&#x53D1;&#x73B0;<code>RenderImage</code>&#x7684;<code>paint</code> &#x65B9;&#x6CD5;&#x4E2D;&#x8C03;&#x7528;&#x4E86;<code>paintImage</code>&#x65B9;&#x6CD5;&#xFF0C;&#x800C;<code>paintImage</code>&#x65B9;&#x6CD5;&#x4E2D;&#x901A;&#x8FC7;<code>Canvas</code>&#x7684;<code>drawImageRect(&#x2026;)</code>&#x3001;<code>drawImageNine(...)</code>&#x7B49;&#x65B9;&#x6CD5;&#x6765;&#x5B8C;&#x6210;&#x6700;&#x7EC8;&#x7684;&#x7ED8;&#x5236;&#x3002;</li>
<li>&#x6700;&#x7EC8;&#x7684;&#x7ED8;&#x5236;&#x7531;<code>RawImage</code>&#x6765;&#x5B8C;&#x6210;&#x3002;</li>
</ol>
<p>&#x4E0B;&#x9762;&#x6D4B;&#x8BD5;&#x4E00;&#x4E0B;<code>MyImage</code>&#xFF1A;</p>
<pre class="language-"><code class="lang-dart"><span class="token keyword">class</span> <span class="token class-name">ImageInternalTestRoute</span> <span class="token keyword">extends</span> <span class="token class-name">StatelessWidget</span> <span class="token punctuation">{</span>
  <span class="token metadata symbol">@override</span>
  Widget <span class="token function">build</span><span class="token punctuation">(</span>BuildContext context<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token function">Column</span><span class="token punctuation">(</span>
      children<span class="token punctuation">:</span> <span class="token operator">&lt;</span>Widget<span class="token operator">&gt;</span><span class="token punctuation">[</span>
        <span class="token function">MyImage</span><span class="token punctuation">(</span>
          imageProvider<span class="token punctuation">:</span> <span class="token function">NetworkImage</span><span class="token punctuation">(</span>
            <span class="token string">&quot;https://avatars2.githubusercontent.com/u/20411648?s=460&amp;v=4&quot;</span><span class="token punctuation">,</span>
          <span class="token punctuation">)</span><span class="token punctuation">,</span>
        <span class="token punctuation">)</span>
      <span class="token punctuation">]</span><span class="token punctuation">,</span>
    <span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x8FD0;&#x884C;&#x6548;&#x679C;&#x5982;&#x56FE;14-4&#x6240;&#x793A;&#xFF1A;</p>
<p><img src="https://pcdn.flutterchina.club/imgs/14-4.png" alt="&#x56FE;14-4"></p>
<p>&#x6210;&#x529F;&#x4E86;&#xFF01; &#x73B0;&#x5728;&#xFF0C;&#x60F3;&#x5FC5;<code>Image</code> Widget&#x7684;&#x6E90;&#x7801;&#x5DF2;&#x7ECF;&#x6CA1;&#x5FC5;&#x8981;&#x5728;&#x82B1;&#x8D39;&#x7BC7;&#x7AE0;&#x53BB;&#x4ECB;&#x7ECD;&#x4E86;&#xFF0C;&#x8BFB;&#x8005;&#x6709;&#x5174;&#x8DA3;&#x53EF;&#x4EE5;&#x81EA;&#x884C;&#x53BB;&#x9605;&#x8BFB;&#x3002;</p>
<h2 id="&#x603B;&#x7ED3;">&#x603B;&#x7ED3;</h2>
<p>&#x672C;&#x8282;&#x4E3B;&#x8981;&#x4ECB;&#x7ECD;&#x4E86;Flutter &#x56FE;&#x7247;&#x7684;&#x52A0;&#x8F7D;&#x3001;&#x7F13;&#x5B58;&#x548C;&#x7ED8;&#x5236;&#x6D41;&#x7A0B;&#x3002;&#x5176;&#x4E2D;<code>ImageProvider</code>&#x4E3B;&#x8981;&#x8D1F;&#x8D23;&#x56FE;&#x7247;&#x6570;&#x636E;&#x7684;&#x52A0;&#x8F7D;&#x548C;&#x7F13;&#x5B58;&#xFF0C;&#x800C;&#x7ED8;&#x5236;&#x90E8;&#x5206;&#x903B;&#x8F91;&#x4E3B;&#x8981;&#x662F;&#x7531;<code>RawImage</code>&#x6765;&#x5B8C;&#x6210;&#x3002; &#x800C;<code>Image</code>&#x6B63;&#x662F;&#x8FDE;&#x63A5;&#x8D77;<code>ImageProvider</code>&#x548C;<code>RawImage</code> &#x7684;&#x6865;&#x6881;&#x3002;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="flutter_app_startup.html" class="navigation navigation-prev " aria-label="Previous page: 14.4：Flutter从启动到显示">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="../chapter15/intro.html" class="navigation navigation-next " aria-label="Next page: 第十五章：一个完整的Flutter应用">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"14.5：Flutter图片加载与缓存","level":"3.7.5","depth":2,"next":{"title":"第十五章：一个完整的Flutter应用","level":"4.1","depth":1,"path":"chapter15/intro.md","ref":"chapter15/intro.md","articles":[{"title":"15.1：应用简介","level":"4.1.1","depth":2,"path":"chapter15/intro.md","ref":"chapter15/intro.md","articles":[]},{"title":"15.2：APP代码结构","level":"4.1.2","depth":2,"path":"chapter15/code_structure.md","ref":"chapter15/code_structure.md","articles":[]},{"title":"15.3：Model类定义","level":"4.1.3","depth":2,"path":"chapter15/models.md","ref":"chapter15/models.md","articles":[]},{"title":"15.4：全局变量及共享状态","level":"4.1.4","depth":2,"path":"chapter15/globals.md","ref":"chapter15/globals.md","articles":[]},{"title":"15.5：网络请求封装","level":"4.1.5","depth":2,"path":"chapter15/network.md","ref":"chapter15/network.md","articles":[]},{"title":"15.6：App入口及首页","level":"4.1.6","depth":2,"path":"chapter15/entry.md","ref":"chapter15/entry.md","articles":[]},{"title":"15.7：登录页","level":"4.1.7","depth":2,"path":"chapter15/login_page.md","ref":"chapter15/login_page.md","articles":[]},{"title":"15.8：多语言和多主题","level":"4.1.8","depth":2,"path":"chapter15/language_and_theme_setting.md","ref":"chapter15/language_and_theme_setting.md","articles":[]}]},"previous":{"title":"14.4：Flutter从启动到显示","level":"3.7.4","depth":2,"path":"chapter14/flutter_app_startup.md","ref":"chapter14/flutter_app_startup.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-search","search-pro","ace","splitter","prism","donate","-highlight"],"root":"docs","styles":{"website":"styles/website.css","ebook":"styles/ebook.css","pdf":"styles/pdf.css","mobi":"styles/mobi.css","epub":"styles/epub.css"},"pluginsConfig":{"prism":{"lang":{"shell":"bash"}},"ace":{},"splitter":{},"search-pro":{"cutWordLib":"nodejieba","defineWord":["Gitbook Use"]},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"donate":{"alipay":"","alipayText":"支付宝打赏","button":"赏","title":"","wechat":"https://pcdn.flutterchina.club/imgs/pay.jpeg","wechatText":"微信打赏"},"fontsettings":{"theme":"white","family":"sans","size":2},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"wendux 824783146@qq.com","bookRoot":"https://book.flutterchina.club/","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"《Flutter实战》","language":"zh-hans","links":{"sharing":{"all":null,"facebook":null,"google":null,"twitter":null,"weibo":null},"sidebar":{"<div><img height=20 style='position:relative; top:5px; padding-right:5px ' src='https://cdn.jsdelivr.net/gh/flutterchina/website@1.0/images/favicon.png'/> Flutter中文网</div>":"https://flutterchina.club"}},"gitbook":"*","description":"记录Gitbook的配置和一些插件的使用"},"file":{"path":"chapter14/image_and_cache.md","mtime":"2019-08-22T07:10:57.363Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-05-05T06:01:05.405Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>



    <script src="https://pcdn.flutterchina.club/gitbook/gitbook.js"></script>
    <script src="https://pcdn.flutterchina.club/gitbook/theme.js"></script>
    
        
        <script src="https://pcdn.flutterchina.club/gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="https://pcdn.flutterchina.club/gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="https://pcdn.flutterchina.club/gitbook/gitbook-plugin-ace/ace/ace.js"></script>
        
    
        
        <script src="https://pcdn.flutterchina.club/gitbook/gitbook-plugin-ace/ace.js"></script>
        
    
        
        <script src="https://pcdn.flutterchina.club/gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="https://pcdn.flutterchina.club/gitbook/gitbook-plugin-donate/plugin.js"></script>
        
    
        
        <script src="https://pcdn.flutterchina.club/gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="https://pcdn.flutterchina.club/gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="https://pcdn.flutterchina.club/gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="https://pcdn.flutterchina.club/gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    


<script src="https://pcdn.flutterchina.club/gitbook/pub.js"></script>
</body>

</html>

